Is there a way to make Maven download snapshot versions automatically?

chrisapotek picture chrisapotek · Oct 10, 2011 · Viewed 39.3k times · Source

So I have a project that depends on a snapshot version of another project. The dependency is:

<dependency>
  <groupId>org.oop</groupId>
  <artifactId>oop</artifactId>
  <version>0.9.9-SNAPSHOT</version>
</dependency>

For the oop project, I did do a 'mvn clean deploy', so the snapshot version should be somewhere in the maven central repository. But when I do a mvn clean install, the snapshot dependency above cannot be resolved and I get this:

Missing:

1) org.oop:oop:jar:0.9.9-SNAPSHOT

Try downloading the file manually from the project website.

Then, install it using the command: mvn install:install-file -DgroupId=org.oop -DartifactId=oop -Dversion=0.9.9-SNAPSHOT -Dpackaging=jar -Dfile=/path/to/file

Alternatively, if you host your own repository you can deploy the file there: mvn deploy:deploy-file -DgroupId=org.oop -DartifactId=oop -Dversion=0.9.9-SNAPSHOT -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]

Is there a way to make maven download the snapshot automatically? I must be missing something here.

EDIT1: On my settings.xml I have:

   <server>
      <id>sonatype-nexus-snapshots</id>
      <username>XXXXXX</username>
      <password>XXXXXX</password>
    </server>

    <server>
      <id>sonatype-nexus-staging</id>
      <username>XXXXXX</username>
      <password>XXXXXX</password>
    </server>

EDIT2: enter image description here

Answer

JohnPristine picture JohnPristine · Oct 10, 2011

Just add this to your ~/.m2/settings.xml:

<profiles>
  <profile>
     <id>allow-snapshots</id>
        <activation><activeByDefault>true</activeByDefault></activation>
     <repositories>
       <repository>
         <id>snapshots-repo</id>
         <url>https://oss.sonatype.org/content/repositories/snapshots</url>
         <releases><enabled>false</enabled></releases>
         <snapshots><enabled>true</enabled></snapshots>
       </repository>
     </repositories>
   </profile>
</profiles>