JHipster configure maven wrapper proxy

2020-02-10 05:14发布

问题:

According to https://jhipster.github.io/configuring-a-corporate-proxy/ I have set up my proxy settings in /.m2/settings.xml like this :

  <proxies>
    <proxy>
      <id>myId</id>
      <active>true</active>
      <protocol>http</protocol>
      <username>myDomain\myUsername</username>
      <password>myPassword</password>
      <host>myHost</host>
      <port>myPort</port>
    </proxy>
  </proxies>

But somehow it is not working when I'm trying to mvnw the project, it's giving me :

Exception in thread "main" java.net.ConnectException: Connection refused: connect

I managed to get it work while passing below parameters to MAVEN_OPTS but I would like to do so with settings.xml file only.

set MAVEN_OPTS=-Dhttps.proxyHost=myHost -Dhttps.proxyPort=myPort -Dhttps.proxyUser=myDomain\myUsername -Dhttps.proxyPassword=myPassword

Anyone can help ?

Thanks in advance.

回答1:

It seems Maven Wrapper does not use the proxy variables from Maven settings. The Downloader does not configure any proxy, so this means Java system properties must be used. For authentication, it just looks for the system property http.proxyUser and uses it.

Setting the MAVEN_OPTS (as you mentioned and also here) works:

set MAVEN_OPTS=-Dhttp.proxyHost=proxyhost -Dhttp.proxyPort=8080 -Dhttps.proxyHost=proxyhost -Dhttps.proxyPort=8080

or

export MAVEN_OPTS=-Dhttp.proxyHost=proxyhost -Dhttp.proxyPort=8080 -Dhttps.proxyHost=proxyhost -Dhttps.proxyPort=8080

The mvnw script also pulls in a file .mvn/jvm.config from the project path which can include these properties:

-Dhttp.proxyHost=host 
-Dhttp.proxyPort=port 
-Dhttps.proxyHost=host 
-Dhttps.proxyPort=port 
-Dhttp.proxyUser=username 
-Dhttp.proxyPassword=password

I've openend a pull request (#446) to add this info to the JHipster documentation.