Table of Contents

Setup Grails 3 Behind Proxy

Most companies have set up proxy to protect, and speed up their network, but grails, and gradle would not download the libraries needed correctly behind the proxy without proper setup.

Proxy Setting for Grails

  1. Go to the path you install grails.
  2. Inside, go to the path bin. My case would be D:\grails-3.3.6\bin.
  3. Use a text editor to open the file grails.bat.
  4. Find the line start with set DEFAULT_JVM_OPTS, and change it to (in one line)
    set DEFAULT_JVM_OPTS="-XX:+TieredCompilation" "-XX:TieredStopAtLevel=1" "-XX:CICompilerCount=3" 
    "-Dhttp.proxyHost=THE_PROXY_PATH" "-Dhttp.proxyPort=THE_PROXY_PORT"
    "-Dhttp.proxyUser=YOUR_USERNAME" "-Dhttp.proxyPassword=YOUR_PASSWORD"
    "-Dhttps.proxyHost=THE_PROXY_PATH" "-Dhttps.proxyPort=THE_PROXY_PORT"
    "-Dhttps.proxyUser=YOUR_USERNAME" "-Dhttps.proxyPassword=YOUR_PASSWORD"
  5. Please change the values of THE_PROXY_PATH, THE_PROXY_PORT, YOUR_USERNAME, YOUR_PASSWORD according to your own setting.
  6. Depending on the proxy server, some of them might only provide http, or https service.
  7. Depending on the proxy server, some of them might not require the user name, and password path.
  8. In either case, your have to omitted the unnecessary parts for the above code.
  9. Save the file.

Proxy Setting for maven or gradle

  1. Go to your own user directory. For Windows 10, it would be C:\Users\YOUR_LOGIN\
  2. Go inside the directory called .m2.
  3. Add a file named settings.xml.
  4. Open settings.xml with a text editor.
  5. Add the following code in such file.
    <settings>
      <proxies>
       <proxy>
          <id>http</id>
          <active>true</active>
          <protocol>http</protocol>
          <host>THE_PROXY_PATH<host>
          <port>THE_PROXY_PORT</port>
          <username>YOUR_USER_NAME</username>
          <password>YOUR_PASSWORD</password>
        </proxy>
       <proxy>
          <id>https</id>
          <active>true</active>
          <protocol>https</protocol>
          <host>THE_PROXY_PATH</host>
          <port>THE_PROXY_PORT</port>
          <username>YOUR_USER_NAME</username>
          <password>YOUR_PASSWORD</password>
        </proxy>
      </proxies>
    </settings>
  6. Depending on the proxy server, some of them might only provide http, or https service.
  7. Depending on the proxy server, some of them might not require the user name, and password path.
  8. In either case, your have to omitted the unnecessary parts for the above code.
  9. Save the file.