jacobduron
jacobduron

Reputation: 431

Gradle can't compile behind proxy

I'm trying to compile an Android project behind a proxy. Most of my dependencies compile fine, but when I add Robolectric to my build.gradle class path I always get errors. So my first proxy configuration is done in Preferences -> HTTP Proxy. When I try to compile with just these settings I get a 407 response:

Error:Could not HEAD 'http://repo1.maven.org/maven2/org/robolectric/robolectric-gradle-plugin/0.12.0/robolectric-gradle-plugin-0.12.0.jar'. Received status code 407 from server: AuthorizedOnly

Which doesn't really make sense because I provide my credentials in the HTTP Proxy settings. Additionally, I try the test-url function on the HTTP Proxy page and it says connection successful.

So then I try adding settings in the gradle.properties file. Which then gives me the following 500 error:

Error:Could not HEAD 'http://repo1.maven.org/maven2/org/robolectric/robolectric-gradle-plugin/0.12.0/robolectric-gradle-plugin-0.12.0.jar'. Received status code 500 from server: ruleengineerror

Are there any settings I'm forgetting? Why are my other dependencies from mavenCentral able to compile? I freshly imported this product so I didn't begin with a cache and if I take the Robolectric out it compiles fine.

Any help would be appreciated. If this is too localized I apologize in advance.

Upvotes: 1

Views: 2626

Answers (2)

jacobduron
jacobduron

Reputation: 431

To anyone who is having trouble with this I finally found a solution that let's me smoothly download all my dependencies behind a proxy.

I'm trying to work behind an NTLM proxy which for me did not cooperate nicely with Gradle. In order to get around this I downloaded SquidMan and set it up. Like some others have suggested in other posts I'm setting up an intermediary proxy to forward my requests and enter my credentials to the main proxy.

Setup:

  1. In SquidMan go to Preferences->General. Here enter proxy configuration for the intermediary proxy. I chose 127.0.0.1 as the host name and port 9090.
  2. Go to parent and enter your corporate/main proxy info.
  3. Start SquidMan
  4. Open the gradle.properties file in the global Gradle location(~/.gradle)
  5. Enter:
    systemProp.http.proxyHost=127.0.0.1 systemProp.http.proxyPort=9090 systemProp.https.proxyHost=127.0.0.1 systemProp.https.proxyPort=9090

Gradle should now be able to smoothly download dependencies behind the proxy.

Hope this helps someone!

Upvotes: 1

Eric Miles
Eric Miles

Reputation: 141

Robolectric leverages Maven configurations for it's dependency resolution (super weird). Take a look at this blog post I wrote for the answer.

Robolectric and Gradle behind Proxies and Firewalls

Just to further this a bit, you'll need to configure your .m2/settings.xml with your proxy information.

Upvotes: 0

Related Questions