New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dependency resolution behind proxy #571

Closed
justinberry opened this Issue Jun 5, 2013 · 11 comments

Comments

Projects
None yet
7 participants
@justinberry

justinberry commented Jun 5, 2013

Hi guys,

I'm using Robolectric 2.1 and I've noticed you have a mechanism in your code for grabbing various dependencies, as listed in SdkConfig.java:

public Dependency[] getSdkClasspathDependencies() {
    return new Dependency[] {
        realAndroidDependency("android-base"),
        realAndroidDependency("android-kxml2"),
        realAndroidDependency("android-luni"),
        createDependency("org.json", "json", "20080701", "jar", null),
        createDependency("org.ccil.cowan.tagsoup", "tagsoup", "1.2", "jar", null)
    };
}

However this isn't working behind our proxy and I'm unable to find any way of configuring this. I'm able to get around this by manually listing these dependencies in our pom.xml file but it's not so nice. Can you offer some guidance here?

Some output for your eyeballs:

mvn clean install output

Cheers

@xian

This comment has been minimized.

Show comment
Hide comment
@xian

xian Jun 5, 2013

Member

Yup! You'll need to extend RobolectricTestRunner for this configuration change. Here's an example:

public class MyRobolectricTestRunner extends RobolectricTestRunner {
  @Override protected void configureMaven(DependenciesTask dependenciesTask) {
    // maybe you want to override this method and some settings?
    RemoteRepository remoteRepository = new RemoteRepository();
    remoteRepository.setId("my private nexus");
    remoteRepository.setUrl("http://my-private-nexus.example.com/nexus/content/repositories/releases");
    dependenciesTask.addConfiguredRemoteRepository(remoteRepository);
  }
}

Then say @RunWith(MyRobolectricTestRunner.class) at the top of your tests!

Member

xian commented Jun 5, 2013

Yup! You'll need to extend RobolectricTestRunner for this configuration change. Here's an example:

public class MyRobolectricTestRunner extends RobolectricTestRunner {
  @Override protected void configureMaven(DependenciesTask dependenciesTask) {
    // maybe you want to override this method and some settings?
    RemoteRepository remoteRepository = new RemoteRepository();
    remoteRepository.setId("my private nexus");
    remoteRepository.setUrl("http://my-private-nexus.example.com/nexus/content/repositories/releases");
    dependenciesTask.addConfiguredRemoteRepository(remoteRepository);
  }
}

Then say @RunWith(MyRobolectricTestRunner.class) at the top of your tests!

@xian xian closed this Jun 5, 2013

@justinberry

This comment has been minimized.

Show comment
Hide comment
@justinberry

justinberry Jun 6, 2013

Kudos for the awesome response time, that worked a treat!

justinberry commented Jun 6, 2013

Kudos for the awesome response time, that worked a treat!

@xian

This comment has been minimized.

Show comment
Hide comment
@xian

xian Jun 6, 2013

Member

Glad to hear it! :-)

Member

xian commented Jun 6, 2013

Glad to hear it! :-)

@domi55

This comment has been minimized.

Show comment
Hide comment
@domi55

domi55 Apr 15, 2014

Omg thanks for this response! I searched like a year for that! :)

domi55 commented Apr 15, 2014

Omg thanks for this response! I searched like a year for that! :)

@nfrankel

This comment has been minimized.

Show comment
Hide comment
@nfrankel

nfrankel Apr 15, 2015

Hi guys,
For me, it's pretty strange not to get the dependencies declared in the POM/build.gradle and do it hard-coded. I'm running behind a proxy, on Jenkins and there's no way we can open http://oss.sonatype.org/. The good thing is we have a Nexus having all libraries.
Would you be open to accept a pull request will necessary libraries set in the POM?

nfrankel commented Apr 15, 2015

Hi guys,
For me, it's pretty strange not to get the dependencies declared in the POM/build.gradle and do it hard-coded. I'm running behind a proxy, on Jenkins and there's no way we can open http://oss.sonatype.org/. The good thing is we have a Nexus having all libraries.
Would you be open to accept a pull request will necessary libraries set in the POM?

@nenick

This comment has been minimized.

Show comment
Hide comment
@nenick

nenick Apr 15, 2015

Contributor

You can provide a custom MavenDependencyResolver at custom RobolectricTestRunner#getJarResolver where you use your repo url sonatypeRepository.setUrl(...)

Another approach is to provide a maven settings.xml where all calls are redirected to your nexus

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
    <mirrors>
        <mirror>
            <id>nexus</id>
            <name>mirror of remote repositories</name>
            <mirrorOf>*</mirrorOf>
            <url>https://<your address>/nexus/content/groups/public</url>
        </mirror>
    </mirrors>
</settings>
Contributor

nenick commented Apr 15, 2015

You can provide a custom MavenDependencyResolver at custom RobolectricTestRunner#getJarResolver where you use your repo url sonatypeRepository.setUrl(...)

Another approach is to provide a maven settings.xml where all calls are redirected to your nexus

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
    <mirrors>
        <mirror>
            <id>nexus</id>
            <name>mirror of remote repositories</name>
            <mirrorOf>*</mirrorOf>
            <url>https://<your address>/nexus/content/groups/public</url>
        </mirror>
    </mirrors>
</settings>
@nfrankel

This comment has been minimized.

Show comment
Hide comment
@nfrankel

nfrankel Apr 15, 2015

Hi Nico,
Thanks for your feedback. The problem with the code approach is that it's not the place to handle dependencies. I guess I'll have to try with the settings.xml, but a colleague told me it didn't work.

nfrankel commented Apr 15, 2015

Hi Nico,
Thanks for your feedback. The problem with the code approach is that it's not the place to handle dependencies. I guess I'll have to try with the settings.xml, but a colleague told me it didn't work.

@nenick

This comment has been minimized.

Show comment
Hide comment
@nenick

nenick Apr 15, 2015

Contributor

I have the same situation (proxy and intranet nexus) and the settings.xml works for me ;)

Contributor

nenick commented Apr 15, 2015

I have the same situation (proxy and intranet nexus) and the settings.xml works for me ;)

@erd

This comment has been minimized.

Show comment
Hide comment
@erd

erd Apr 15, 2015

Member

Would you be open to accept a pull request will necessary libraries set in the POM?

The reason they're not listed in the pom is that the android-all jars are around 50MB each, so requiring users to download all of them could be prohibitive. There is a way to run robolectric in "offline" mode, where you manually download all the dependencies and tell robolectric where to find them. Unfortunately, it's not well documented.

Member

erd commented Apr 15, 2015

Would you be open to accept a pull request will necessary libraries set in the POM?

The reason they're not listed in the pom is that the android-all jars are around 50MB each, so requiring users to download all of them could be prohibitive. There is a way to run robolectric in "offline" mode, where you manually download all the dependencies and tell robolectric where to find them. Unfortunately, it's not well documented.

@nfrankel

This comment has been minimized.

Show comment
Hide comment
@nfrankel

nfrankel Apr 19, 2015

I don't see your point. Every build system (Maven, Gradle, etc.) has a way to exclude dependencies. Besides, they are downloaded only once and put in a cache. Even better, if you have an entreprise repository like Artifactory or Nexus, you pay the download cost only once across all enterprise.

On the other hand, having a library downloading its dependencies in the code with the repository hard-coded (oss.sonatype.org) defeats the least surprise principle.

As for the offline mode, I stumbled upon it but you have to put every dependency in the same folder - flat hierarchy, which build systems are not made for.

nfrankel commented Apr 19, 2015

I don't see your point. Every build system (Maven, Gradle, etc.) has a way to exclude dependencies. Besides, they are downloaded only once and put in a cache. Even better, if you have an entreprise repository like Artifactory or Nexus, you pay the download cost only once across all enterprise.

On the other hand, having a library downloading its dependencies in the code with the repository hard-coded (oss.sonatype.org) defeats the least surprise principle.

As for the offline mode, I stumbled upon it but you have to put every dependency in the same folder - flat hierarchy, which build systems are not made for.

@daj

This comment has been minimized.

Show comment
Hide comment
@daj

daj Sep 7, 2016

The configureMaven method no longer exists in RobolectricTestRunner, so the solution above doesn't work. For anybody looking for a solution for this problem using Gradle on Robolectric 3.0, see this Stackoverflow answer: http://stackoverflow.com/a/39360538/112705

daj commented Sep 7, 2016

The configureMaven method no longer exists in RobolectricTestRunner, so the solution above doesn't work. For anybody looking for a solution for this problem using Gradle on Robolectric 3.0, see this Stackoverflow answer: http://stackoverflow.com/a/39360538/112705

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment