50

So I have a project and I do regular releases to maven without a problem. I now want to make available a SNAPSHOT version of this project. So I do 'mvn clean deploy'. Everything works as you can see below:

[INFO] Retrieving previous build number from sonatype-nexus-snapshots Uploading: https://oss.sonatype.org/content/repositories/snapshots/me/soliveirajr/menta-regex/0.9.6-SNAPSHOT/menta-regex-0.9.6-20111010.153035-2.jar 5K uploaded (menta-regex-0.9.6-20111010.153035-2.jar)

I go to my sonatype manager and I can find the snapshot: enter image description hereenter image description here

But now when I try to use this snapshot as a dependency on some other project in another machine I get:

<dependency>
  <groupId>me.soliveirajr</groupId>
  <artifactId>menta-regex</artifactId>
  <version>0.9.6-SNAPSHOT</version>
</dependency>

Missing:

1) me.soliveirajr:menta-regex:jar:0.9.6-SNAPSHOT

Try downloading the file manually from the project website.

Then, install it using the command: mvn install:install-file -DgroupId=me.soliveirajr -DartifactId=menta-regex -Dversion=0.9.6-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=me.soliveirajr -DartifactId=menta-regex -Dversion=0.9.6-SNAPSHOT -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]

So how do I force maven to download the SNAPSHOT version to my local (.m2) repository?

3 Answers 3

73

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>
1
  • 4
    Nice example, to any readers: please note if you're looking for JaCoCo latest snapshot, don't make the same mistake as I did and copy this example. Because it's a plugin and they have different repo's. See this answer: stackoverflow.com/a/46682942/1546042
    – BitfulByte
    Dec 7, 2017 at 13:00
32

For the sake of completeness, I would like to add that it is also possible by modifying the pom.xml of a project, simply add

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

to your list of repositories.

In my opinion, this is a better solution than modifying ~/.m2/settings.xml. The pom.xml file will also be available for other project participants through Git and allow them to download the snapshots as well.

Source: this answer

4
  • 2
    This was super helpful. Small note for those not having a <repositories> section, you will need a tag at the beginning of this chunk of code, and it goes at the same level as properties and dependencies.
    – Doug Noel
    Apr 16, 2020 at 17:19
  • Thanks, added the missing start tag! Aug 28, 2020 at 12:39
  • 1
    This is example of how to use SNAPSHOT artifact of regular dependencies and plugins github.com/checkstyle/checkstyle/wiki/… Aug 28, 2020 at 14:03
  • Can use settings.xml in the repo? Then, Git users would get that.
    – khatchad
    Jan 17 at 17:40
1

You can enable snapshots in repository config (~/.m2/settings.xml):

<settings>
    <profiles>
        <profile>
          <repositories>
            <repository>
              <snapshots>                  <<<<<<<<<<<
                <enabled>true</enabled>    << ADD THIS
              </snapshots>                 <<<<<<<<<<<
  . . .
</settings>

See maven.apache.org/settings.html#Repositories for more properties.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.