【问题标题】:Proxies in Maven's settings.xmlMaven 的 settings.xml 中的代理
【发布时间】:2017-03-29 17:15:57
【问题描述】:

来自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 中做错了什么?

【问题讨论】:

    标签: proxy maven-3


    【解决方案1】:

    在阅读了检查的答案后,我试图让它全部工作,实际上只需要修复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>
    

    所以我把这个留在这里,以防有人偶然发现同样的误解......

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-09-16
        • 2015-05-16
        • 1970-01-01
        • 2015-09-10
        • 1970-01-01
        相关资源
        最近更新 更多