2011-11-24 4 views
10

httpunit를 사용하여 서버에 액세스하고 있습니다.Maven + 확신 : 프록시 구성

이 (http 및 https)에 대한 프록시 설정을 구성해야합니다.

settings.xml 파일에서 구성을 설정했지만 확실하게 무시하는 것 같습니다!

가능한 한 구성을 복제하지 않으려합니다.

는 확실한 플러그인 구성에서 나는 시도 :

<systemPropertyVariables> 
    <http.proxyHost>${http.proxyHost}</http.proxyHost> 
</systemPropertyVariables> 

<argLine>-Dhttp.proxyHost=${http.proxyHost}</argLine> 

<argLine>-Dhttp.proxyHost=${settings.proxies[protocol=http].host}</argLine> 

여러 다른 조합을.

나는 함께 단위 테스트에서 시스템 등록 정보를 인쇄 :

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

까지 같은 명시적인 값이다 그래서 일을하는 유일한 것은 :

<systemPropertyVariables> 
    <http.proxyHost>myProxy</http.proxyHost> 
</systemPropertyVariables> 

또는

<argLine>-Dhttp.proxyHost=myProxy</argLine> 

가 하지만 내가 말했듯이 가능한 경우 구성을 복제하고 싶지 않습니다.

단위 테스트에서 settings.xml 파일에 설정된 프록시 설정은 어떻게 사용할 수 있습니까?

+0

'settings.xml '에서'http.proxyHost'를'property'로 갖는 것은 어떻습니까? 나는 현재'proxy' 설정 값을 사용하려고합니다. – Raghuram

답변

1

Maven Surefire 플러그인의 forkMode 기본값은 "once"입니다. 이 설정을 "never"로 설정하고 빌드를 다시 실행 해보는 것이 좋습니다. 내 이론은 여기에 Surefire 플러그인이 새로운 JVM을 포크하기 때문에 시스템 속성을 잃어 버리는 것입니다.

+0

Surefire는 의도적으로 시스템 특성을 "느슨하게"합니다 - 테스트 환경을 깨끗하게 제공하는 것처럼 가장합니다. – Anton

0

편집 Maven의 settings.xml 파일을 편집하면 프록시가 제대로 작동합니다. 우분투와 AWS 리눅스에서 경로 /var/lib/jenkins/tools/hudson.tasks.Maven_MavenInstallation/maven/conf

<!-- proxy 
| Specification for one proxy, to be used in connecting to the network. 
| 
<proxy> 
    <id>optional</id> 
    <active>true</active> 
    <protocol>http</protocol> 
    <username>proxyuser</username> 
    <password>proxypass</password> 
    <host>proxy.host.net</host> 
    <port>80</port> 
    <nonProxyHosts>local.net|some.host.com</nonProxyHosts> 
</proxy> 
--> 
3

내가 필요로 할 때 시스템 속성을 통해 받는다는 모든 프록시 관련 설정, 플러스 약간의 비틀기를 제공하여 런타임에 감지하는 것을 해결하는 경우 내 부모 POM에 존재하는 이러한 설정.

1) 프록시 설정이 필요한 환경에서는 MAVEN_OPTS으로 Maven ("~/.mavenrc" 또는 "%PROFILE%\mavenrc_pre.bat")의 RC 파일을 만듭니다.

set MAVEN_OPTS=-Dhttp.proxyHost=10.0.1.250 -Dhttp.proxyPort=3128 -Dhttp.nonProxyHosts="localhost|*.local|*.mylab.com" 

2) 프록시 설정을 제공 한 경우 검색 및 확실한에 대한 인수를 구축 : 예를 들어

<plugin> 
    <groupId>org.codehaus.gmaven</groupId> 
    <artifactId>groovy-maven-plugin</artifactId> 
    <version>2.0</version> 
    <executions> 
     <execution> 
      <phase>initialize</phase> 
      <goals> 
       <goal>execute</goal> 
      </goals> 
     </execution> 
    </executions> 
    <configuration> 
     <source> 
      <![CDATA[ 
       // Collect proxy settings to use in Surefire and Failsafe plugins 
       def settings = ""; 
       System.properties.each { k,v -> 
        if (k.startsWith("http.") || k.startsWith("https.")) 
        { 
         // We have to escape pipe char in 'nonProxyHosts' on Windows 
         if (System.properties['os.name'].toLowerCase().contains('windows')) 
          v = v.replaceAll("\\|", "^|"); 
         settings += "-D$k=$v "; 
        } 
       } 
       project.properties["proxy.settings"] = settings; 
      ]]> 
     </source> 
    </configuration> 
</plugin> 

3) 사용은 확실한에서 인수 및 안전 장치 플러그인 준비 :

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-surefire-plugin</artifactId> 
    <version>2.18.1</version> 
    <configuration> 
     <argLine>${proxy.settings}</argLine> 
     <redirectTestOutputToFile>true</redirectTestOutputToFile> 
    </configuration> 
</plugin> 
<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-failsafe-plugin</artifactId> 
    <version>2.18.1</version> 
    <configuration> 
     <argLine>${proxy.settings}</argLine> 
     <redirectTestOutputToFile>true</redirectTestOutputToFile> 
    </configuration> 
</plugin> 

을 즐길 수 :)