Home  >  Article  >  Java  >  How to Configure Gradle to Use a Proxy Server?

How to Configure Gradle to Use a Proxy Server?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-11-02 04:55:29721browse

How to Configure Gradle to Use a Proxy Server?

Gradle Proxy Configuration

Configuring Gradle to access the internet through a proxy server is crucial for seamless integration with remote repositories or third-party services. When using the build-info-extractor-gradle plugin to connect to Artifactory, it's essential to specify the proxy settings correctly.

To set up HTTP or HTTPS proxy configuration, add the following properties to your .gradle/gradle.properties file:

  • For HTTP only proxy: -Dhttp.proxyHost=[host name] and -Dhttp.proxyPort=[port number]
  • For HTTPS only proxy: -Dhttps.proxyHost=[host name] and -Dhttps.proxyPort=[port number]
  • For both HTTP and HTTPS proxy: specify both the HTTP and HTTPS properties as above

To provide credentials for the proxy, include these properties: -Dhttp.proxyUser=[user name] and -Dhttp.proxyPassword=[password] (or -Dhttps.proxyUser and -Dhttps.proxyPassword for HTTPS proxies).

To exclude specific hosts from proxy tunneling, use the -Dhttp.nonProxyHosts=[host names] property.

Example:

Consider the following scenario:

  • Proxy host: 127.0.0.1
  • Proxy port: 3128
  • Proxy user: user
  • Proxy password: pass
  • Hosts to bypass proxy: host1.com, host2.com

To configure Gradle with this proxy, add the following properties to your .gradle/gradle.properties file:

-Dhttp.proxyHost=127.0.0.1
-Dhttp.proxyPort=3128
-Dhttp.proxyUser=user
-Dhttp.proxyPassword=pass
-Dhttp.nonProxyHosts=host1.com|host2.com

Remember, you can also set these properties in gradle-wrapper.properties for project-wide proxy configuration.

The above is the detailed content of How to Configure Gradle to Use a Proxy Server?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn