Chr*_*ian 5 macos proxy socks maven maven-surefire-plugin
我试图阻止 maven 3.3.9(在 Mac OS 10.12.3 和 Java 1.8.0_121 上运行)使用系统偏好设置中定义的 SOCKS 代理。
\n\n我已经proxy从我的settings.xml.
在我的 中.bash_profile,我设置了以下内容:
export MAVEN_OPTS="\n-Dhttp.proxyHost=proxy.example.com -Dhttp.proxyPort=80 \\\n-Dhttps.proxyHost=proxy.example.com -Dhttps.proxyPort=80 \\\n-Dhttp.nonProxyHosts=localhost|foo.example.com|*.bar.example.com|*.baz.example.com \\\n-Dhttps.nonProxyHosts=localhost|foo.example.com|*.bar.example.com|*.baz.example.com \\\n-DsocksProxyHost -DsocksProxyPort"\n当我运行时mvn help:effective-settings,我得到以下信息:
<settings xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">\n  <localRepository xmlns="http://maven.apache.org/SETTINGS/1.1.0">/java/.m2/repository</localRepository>\n  <servers xmlns="http://maven.apache.org/SETTINGS/1.1.0">\n    <!-- ... -->\n  </servers>\n  <mirrors xmlns="http://maven.apache.org/SETTINGS/1.1.0">\n    <mirror>\n      <mirrorOf>*</mirrorOf>\n      <url>http://nexus.example.com:nnnn/...</url>\n      <id>nexus</id>\n    </mirror>\n  </mirrors>\n  <profiles xmlns="http://maven.apache.org/SETTINGS/1.1.0">\n    <profile>\n      <repositories>\n        <repository>\n          <releases />\n          <snapshots />\n          <id>central</id>\n          <url>http://central</url>\n        </repository>\n      </repositories>\n      <pluginRepositories>\n        <pluginRepository>\n          <releases />\n          <snapshots />\n          <id>central</id>\n          <url>http://central</url>\n        </pluginRepository>\n      </pluginRepositories>\n      <id>nexus</id>\n    </profile>\n  </profiles>\n  <activeProfiles xmlns="http://maven.apache.org/SETTINGS/1.1.0">\n    <activeProfile>nexus</activeProfile>\n  </activeProfiles>\n  <pluginGroups xmlns="http://maven.apache.org/SETTINGS/1.1.0">\n    <pluginGroup>org.apache.maven.plugins</pluginGroup>\n    <pluginGroup>org.codehaus.mojo</pluginGroup>\n  </pluginGroups>\n</settings>\n正如您所看到的,它根本不包含proxy任何部分。这是否意味着它没有从MAVEN_OPTS环境变量中获取代理设置?
实际问题是我们在系统偏好设置中定义了 SOCKS 代理设置(我不想停用),但当该设置打开时,maven 构建(即 JUnit 集成测试)会失败 ( ) Caused by: java.net.SocketException: SOCKS: Connection not allowed by ruleset。一旦停用,构建就会通过。
所以我想覆盖maven的系统设置,禁用SOCKS代理设置。但看起来它并没有读取覆盖?
\n\n我还尝试在我的 maven 中设置 SOCKS 代理settings.xml,但这也没有达到预期的效果(大概是因为您不能在 中设置 SOCKS 代理settings.xml,或者因为您不能从袜子代理中排除主机(有没有-D可用的等效选项)):
<proxy>\n  <id>no-socks-proxy</id>\n  <active>true</active>\n  <protocol>socks</protocol>\n  <host>socksproxy.example.com</host>\n  <port>nnnn</port>\n  <nonProxyHosts>*</nonProxyHosts>\n</proxy>\n知道我需要做什么来阻止 Maven 获取系统 SOCKS 设置吗?
\n\n更新
\n\n我刚刚检查过,终端显示以下内容正在执行:
\n\njava \'-Dhttp.proxyHost=proxy.example.com\xe2\x80\x99 \'-Dhttp.proxyPort=80\' \'-Dhttps.proxyHost=proxy.example.com\xe2\x80\x99 \'-Dhttps.proxyPort=80\' \'-Dhttp.nonProxyHosts=localhost|\xe2\x80\xa6\xe2\x80\x99 \'-Dhttps.nonProxyHosts=localhost|\xe2\x80\xa6\xe2\x80\x99 -DsocksProxyHost -DsocksProxyPort -classpath /.../apache-maven/boot/plexus-classworlds-2.5.2.jar \'-Dclassworlds.conf=/.../apache-maven/bin/m2.conf\' \'-Dmaven.home=/.../apache-maven\' \'-Dmaven.multiModuleProjectDirectory=/.../foo/trunk/bar\xe2\x80\x99 org.codehaus.plexus.classworlds.launcher.Launcher clean install\n\n...\n\njava \'-javaagent:/.../.m2/repository/org/jacoco/org.jacoco.agent/0.7.8/org.jacoco.agent-0.7.8-runtime.jar=destfile=/.../foo/trunk/bar/baz/target/jacoco.exec\' -jar /.../foo/trunk/bar/baz/target/surefire/surefirebooternnnnnnn.jar /.../foo/trunk/bar/baz/target/surefire/surefirennnnnnntmp /.../foo/trunk/bar/baz/target/surefire/surefire_nnnnntmp\n这让我认为这些设置确实被父进程获取mvn,但它们不会传递给子进程(即surefire)。
顺便说一句,设置export JAVA_TOOL_OPTIONS="-DsocksProxyHost -DsocksProxyPort"强制它们进入子进程,并且我的构建通过(而设置export JAVA_OPTS="-DsocksProxyHost -DsocksProxyPort"没有效果)。
有没有办法强制JAVA_OPTIONS进入maven的子进程,而不使用JAVA_TOOL_OPTIONS(并且不按照surefire手册更改POM )?
| 归档时间: | 
 | 
| 查看次数: | 6510 次 | 
| 最近记录: |