运行mvn时没有反映MAVEN_OPTS代理设置帮助:有效设置 - 如何阻止mvn使用系统定义的SOCKS代理?

时间:2017-03-17 17:43:19

标签: macos maven proxy maven-surefire-plugin socks

我试图使用系统偏好设置中定义的SOCKS代理停止maven 3.3.9(在Mac OS 10.12.3和Java 1.8.0_121上运行)。

我已从proxy删除了所有settings.xml个元素。

在我的.bash_profile中,我设置了以下内容:

export MAVEN_OPTS="
-Dhttp.proxyHost=proxy.example.com -Dhttp.proxyPort=80 \
-Dhttps.proxyHost=proxy.example.com -Dhttps.proxyPort=80 \
-Dhttp.nonProxyHosts=localhost|foo.example.com|*.bar.example.com|*.baz.example.com \
-Dhttps.nonProxyHosts=localhost|foo.example.com|*.bar.example.com|*.baz.example.com \
-DsocksProxyHost -DsocksProxyPort"

当我运行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">
  <localRepository xmlns="http://maven.apache.org/SETTINGS/1.1.0">/java/.m2/repository</localRepository>
  <servers xmlns="http://maven.apache.org/SETTINGS/1.1.0">
    <!-- ... -->
  </servers>
  <mirrors xmlns="http://maven.apache.org/SETTINGS/1.1.0">
    <mirror>
      <mirrorOf>*</mirrorOf>
      <url>http://nexus.example.com:nnnn/...</url>
      <id>nexus</id>
    </mirror>
  </mirrors>
  <profiles xmlns="http://maven.apache.org/SETTINGS/1.1.0">
    <profile>
      <repositories>
        <repository>
          <releases />
          <snapshots />
          <id>central</id>
          <url>http://central</url>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <releases />
          <snapshots />
          <id>central</id>
          <url>http://central</url>
        </pluginRepository>
      </pluginRepositories>
      <id>nexus</id>
    </profile>
  </profiles>
  <activeProfiles xmlns="http://maven.apache.org/SETTINGS/1.1.0">
    <activeProfile>nexus</activeProfile>
  </activeProfiles>
  <pluginGroups xmlns="http://maven.apache.org/SETTINGS/1.1.0">
    <pluginGroup>org.apache.maven.plugins</pluginGroup>
    <pluginGroup>org.codehaus.mojo</pluginGroup>
  </pluginGroups>
</settings>

正如您所看到的,它根本不包含proxy部分。这是否意味着它没有从MAVEN_OPTS环境变量中获取代理设置?

实际问题是我们在系统偏好设置(我不想停用)中定义了SOCKS代理设置,但是当启用时,maven构建(即JUnit集成测试)失败({{1 }})。一旦停用,构建就会通过。

所以我想覆盖maven的系统设置,禁用SOCKS代理设置。然而,它看起来不像是覆盖了这些内容吗?

我还试图在我的maven Caused by: java.net.SocketException: SOCKS: Connection not allowed by ruleset中设置一个SOCKS代理,但这也没有产生预期的效果(可能是因为你不能在settings.xml中设置SOCKS代理,或者因为您无法从socks代理中排除主机(没有可用的等效settings.xml选项)):

-D

知道我需要做些什么才能阻止maven获取系统SOCKS设置?

更新

我刚检查过,终端说下面的内容正在执行:

<proxy>
  <id>no-socks-proxy</id>
  <active>true</active>
  <protocol>socks</protocol>
  <host>socksproxy.example.com</host>
  <port>nnnn</port>
  <nonProxyHosts>*</nonProxyHosts>
</proxy>

这让我觉得设置确实被父java '-Dhttp.proxyHost=proxy.example.com’ '-Dhttp.proxyPort=80' '-Dhttps.proxyHost=proxy.example.com’ '-Dhttps.proxyPort=80' '-Dhttp.nonProxyHosts=localhost|…’ '-Dhttps.nonProxyHosts=localhost|…’ -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’ org.codehaus.plexus.classworlds.launcher.Launcher clean install ... java '-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 进程接收,但他们没有被传递给子进程(即mvn)。

顺便提一下,设置surefire会强制它们进入子进程,并且我的构建通过(而设置export JAVA_TOOL_OPTIONS="-DsocksProxyHost -DsocksProxyPort"则没有效果。)

有没有办法强制export JAVA_OPTS="-DsocksProxyHost -DsocksProxyPort"进入maven的子进程,而不使用JAVA_TOOL_OPTIONS(并且不按照surefire manual更改POM)?

0 个答案:

没有答案