Maven 中的代理 settings.xml

Proxies in Maven's settings.xml

来自 this question 我正在尝试让我的设置正常工作,但测试一直失败,因为它们无法连接到远程站点。我升级到 Maven 3.3.9.

这是我想要开始工作的settings.xml

<settings>

  <proxies>
    <proxy>
      <id>httpProxy</id>
      <active>true</active>
      <protocol>http</protocol>
      <host>proxy.local</host>
      <port>3128</port>
      <nonProxyHosts>localhost|*.local</nonProxyHosts>
    </proxy>
    <proxy>
      <id>httpsProxy</id>
      <active>true</active>
      <protocol>https</protocol>
      <host>10.20.20.208</host>
      <port>3128</port>
      <nonProxyHosts>localhost|*.local</nonProxyHosts>
    </proxy>
  </proxies>
:

这是一小部分,已经不起作用了:

<settings>

  <proxies>
    <proxy>
      <protocol>https</protocol>
      <host>10.20.20.208</host>
      <port>3128</port>
    </proxy>
  </proxies>
:

我也试过把 IP 地址放在那里。

我知道 Maven 选择 XML,因为 Maven 在它的调试消息中这样说,如果我破坏它的语法,Maven 会抱怨。

唯一真正有效的是将 -Dhttps.proxyHost=proxy.local -Dhttps.proxyPort=3128 传递给 Maven。

我在 XML 中做错了什么?

您的测试可能不会读取 settings.xml,因为那是针对 Maven 的,因为那是针对 Maven 构建及其插件的。

您可以通过添加 -X 来仔细检查这一点,并查看当 surefire 为 运行 时发送到您的测试的属性。

阅读已检查的答案后,我尝试使其全部正常工作,实际上只需要修复 maven-failsafe-plugin:

的插件配置
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>2.8</version>
    <executions>
      <execution>
        <id>integration-test</id>
        <goals>
          <goal>integration-test</goal>
        </goals>
        <configuration>
          <!-- added -Dhttps.proxyHost and -Dhttps.proxyPort -->
          <argLine>-Xmx512m -XX:MaxPermSize=512m -Dhttps.proxyHost=proxy.local -Dhttps.proxyPort=3128</argLine>
          <includes>
            <include>**/*ITest.java</include>
          </includes>
        </configuration>
      </execution>
      <execution>
        <id>verify</id>
        <goals>
          <goal>verify</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

所以我把它留在这里,以防有人遇到同样的误解...