简体   繁体   中英

Run Robolectric in IDEA behind the proxy

I have corporate environment with all http and https calls are behind the proxy.

I was able to fix some issues with command line downloads by putting exporting http_proxy environment variable into .profile file.

But with Robolectric 2.2 which is downloading android sources or classes before first run I failed. I don't have CI setup yet so I'm just trying to run tests from idea.

Does anyone know hot to fix it?

I've tried to provide proxy in IDEA settings, I've tried to provide additional environment variable in run configuration. Nothing helps

UPD When I specify proxy in Mac settings it is producing another error: Unable to find resource 'org.sonatype.oss:oss-parent:pom:7' in repository sonatype ( https://oss.sonatype.org/content/groups/public/ )

It looks like I'm probably using or missing wrong transitive dependency for Robolectirc (I don't use maven or ivy, I've just downloaded jars from maven central)

UPD2 Nope, It is just timeout again: Error transferring file: Operation timed out

I know that this is a little bit old Question but if you want to use proxy you should put the following file in your home/.m2 directory:

settings.xml

<settings>
    <proxies>
        <proxy>
            <active>true</active>
            <protocol>http</protocol>
            <host>your_host_here</host>
            <port>your_port_here</port>
        </proxy>
    </proxies>
</settings>

For gradle look here https://docs.gradle.org/current/userguide/build_environment.html

To add another late answer to an old question :) Since Robolectric 2.4 two properties were introduced to help in the scenario when your Robolectric tests in CI run behind a proxy server:

You have to specify robolectric.offline and robolectric.dependency.dir in your build.gradle file. Something like this:

afterEvaluate {
    project.tasks.withType(Test) {
        systemProperties.put('robolectric.offline', 'true')
        systemProperties.put('robolectric.dependency.dir', "${project.rootDir}/.robolectric/")
    }
}

Then you need to download the necessary jars from maven or sonatype and place it in the directory you specified...

I wrote a blog post with more details.

In case this helps someone. Setting the proxy in settings.xml (I tried both possible paths for this file) did not work for me. I ended up passing that as a gradle arguments: gradle cleanTest test -Dhttps.proxyHost=<proxy-host> -Dhttps.proxyPort=<proxy-port>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM