How do you import a Maven dependency from Sonatype.org?

Christopher Perry picture Christopher Perry · Dec 19, 2012 · Viewed 13.5k times · Source

I'm trying to import Robolectric into my Maven project, with:

        <dependency>
            <groupId>com.pivotallabs</groupId>
            <artifactId>robolectric</artifactId>
            <version>1.2-SNAPSHOT</version>
            <scope>test</scope>
        </dependency>

The artifact is listed here:

https://oss.sonatype.org/index.html#nexus-search;quick~robolectric

I tried including:

<repositories>
    <repository>
        <id>oss-sonatype</id>
        <name>oss-sonatype</name>
        <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>

as suggested from this post, but it doesn't resolve robolectric.

Answer

Manfred Moser picture Manfred Moser · Dec 19, 2012

This should work although you should really install a repository manager like Sonatype Nexus and proxy the oss snapshot repository.

In your case the problem might be that it did not find it previously and that fact is cached in your local repository. To force Maven to check agagin use the -U flag so e.g. run

mvn -U clean install