Running unit tests fails behind a proxy

Hi, I’m running my Android Gradle tasks on a Jenkins server which is behind a proxy. By setting the the proxy settings to my the builds just work fine and Gradle can also download its dependencies from the web using the gradle wrapper.
./gradlew assemblePaidFlavorDebug

But if I try to execute tests that are located in one project module by
./gradlew communicationModule:test
, which need to connect to a webservice in the internet, I get for all tests

The linux server itself also has the proxy settings set.
When running the tests locally without a proxy they all complete successfully.
Do I need to set the proxy somewhere else for the unit tests?

Thanks for your help!

you should be able to pass proxy properties to the Test task using the jmvArgs property. Have you tried passing proxy settings using this property?

Hi Rene, thanks for your reply. Do you mean overwriting the test task and define the gradle properties or can I pass them directly when I call it through the gradle wrapper? Can you give me an example on how to do it?


you don’t need to overwrite your test task(s). you just can add additional configuration. I meantioned the jvmArgs in my former reply. Using systemProperty is even simpler I guess.

Assuming you have a simple java project with a test task named test:

test {
    systemProperty "http.proxyHost", "yourproxyHost" 
    systemProperty "http.proxyPort", "yourproxyPort"    

if you want to configure all your tasks of type Test you can simply do

tasks.withType(Test) {
    systemProperty "http.proxyHost", "yourproxyHost" 
    systemProperty "http.proxyPort", "yourproxyPort"    


Hey René,

thanks for the samples. I tried now the following options:

android { tasks.withType(Test) { systemProperty "http.proxyHost" "proxy.muc" systemProperty "http.proxyPort" "8080" systemProperty "http.proxyUser" "user" systemProperty "http.proxyPassword" "pwd" systemProperty "https.proxyHost" "proxy.muc" systemProperty "https.proxyPort" "8080" systemProperty "https.proxyUser" "user" systemProperty "https.proxyPassword" "pwd" } }
which gives me:
Could not find method systemProperty() for arguments [http.proxyHost] on task ':communicationModule:testDebugUnitTest'.

test { <same args as above> }
i get (no matter of inside or outside the android block)
Could not find method test() for arguments [build_1le2oyl00m1ganma0nwiyz1om$_run_closure1$_closure7@609b041c] on project ':communicationModule'

Trying the following line at least gives no Gradle compile error…
android { testOptions { unitTests.all { jvmArgs '-Dhttp.proxyHost=proxy.muc -Dhttp.proxyPort=8080 -Dhttp.proxyUser=user -Dhttp.proxyPassword=pwd -Dhttps.proxyHost=proxy.muc -Dhttps.proxyPort=8080 -Dhttps.proxyUser=user -Dhttps.proxyPassword=pwd' } } }

but I still get the

I was reading that if I need proxy authentication I need to touch my Java code as system properties do not work out of the box, but Gradle itself works when setting host, port, username and password in the

Any idea why it’s still not working? Thanks again!

sorry I forgot to put colons in my snippet. it should be 'systemProperty 'key', 'value'

where have you read this?

They say in this post that you also have to overwrite Authenticator