Maven + Surefire:代理配置

Puc*_*uce 10 java proxy maven http-unit maven-surefire-plugin

我正在使用httpunit来访问服务器.

我需要为此配置代理设置(http和https).

我在settings.xml文件中设置了配置,但是确定似乎忽略了它!?

我想避免尽可能复制配置.

在surefire插件配置中我试过:

<systemPropertyVariables>
    <http.proxyHost>${http.proxyHost}</http.proxyHost>
</systemPropertyVariables>
Run Code Online (Sandbox Code Playgroud)

<argLine>-Dhttp.proxyHost=${http.proxyHost}</argLine>
Run Code Online (Sandbox Code Playgroud)

<argLine>-Dhttp.proxyHost=${settings.proxies[protocol=http].host}</argLine>
Run Code Online (Sandbox Code Playgroud)

和其他几个组合.

我在单元测试中打印系统属性:

for (String propertyName : new TreeSet<String>(System.getProperties().stringPropertyNames())){
        System.out.println(propertyName + ": " + System.getProperty(propertyName));
    }
Run Code Online (Sandbox Code Playgroud)

到目前为止唯一有效的是显式值,例如:

<systemPropertyVariables>
    <http.proxyHost>myProxy</http.proxyHost>
</systemPropertyVariables>
Run Code Online (Sandbox Code Playgroud)

要么

<argLine>-Dhttp.proxyHost=myProxy</argLine>
Run Code Online (Sandbox Code Playgroud)

但正如我所说,如果可能的话,我不想复制配置.

如何在单元测试中使用settings.xml文件中设置的代理设置?

Tim*_*ien 1

Maven Surefire 插件的 forkMode 默认为“once”。我建议将其设置为“从不”,然后尝试再次运行构建。我的理论是,您正在丢失系统属性,因为 Surefire 插件正在分叉一个新的 JVM。