简体   繁体   English

在代理后面的IDEA中运行Robolectric

[英]Run Robolectric in IDEA behind the proxy

I have corporate environment with all http and https calls are behind the proxy. 我有企业环境,所有http和https调用都在代理后面。

I was able to fix some issues with command line downloads by putting exporting http_proxy environment variable into .profile file. 通过将http_proxy环境变量导出到.profile文件中,我能够解决命令行下载的一些问题。

But with Robolectric 2.2 which is downloading android sources or classes before first run I failed. 但是在第一次运行之前下载Android源代码或类的Robolectric 2.2我失败了。 I don't have CI setup yet so I'm just trying to run tests from idea. 我还没有CI设置,所以我只是想从想法中运行测试。

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. 我试图在IDEA设置中提供代理,我试图在运行配置中提供额外的环境变量。 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/ ) UPD当我在Mac设置中指定代理时,它产生另一个错误: 无法在存储库sonatype中找到资源'org.sonatype.oss:oss-parent:pom:7'( 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) 看起来我可能正在使用或缺少Robolectirc错误的传递依赖(我不使用maven或常春藤,我刚从maven中心下载了罐子)

UPD2 Nope, It is just timeout again: Error transferring file: Operation timed out UPD2没有 ,它只是暂停: 传输文件时出错:操作超时

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: 我知道这有点旧问题,但是如果你想使用代理,你应该将以下文件放在你的home / .m2目录中:

settings.xml 的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 有关gradle的信息,请访问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: 为旧问题添加另一个迟到的答案:)由于Robolectric 2.4引入了两个属性来帮助您在CI中运行的Robolectric测试在代理服务器后运行:

You have to specify robolectric.offline and robolectric.dependency.dir in your build.gradle file. 您必须在build.gradle文件中指定robolectric.offlinerobolectric.dependency.dir 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... 然后你需要从maven或sonatype下载必要的jar并将它放在你指定的目录中...

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. 在settings.xml中设置代理(我尝试了这个文件的两个可能路径)对我来说不起作用。 I ended up passing that as a gradle arguments: gradle cleanTest test -Dhttps.proxyHost=<proxy-host> -Dhttps.proxyPort=<proxy-port> 我最终将其作为gradle参数传递: gradle cleanTest test -Dhttps.proxyHost=<proxy-host> -Dhttps.proxyPort=<proxy-port>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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