22

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

chrisapotek
  • 6,007
  • 14
  • 51
  • 85

7 Answers7

24

To update snapshots, try with the -U option

-U,--update-snapshots                  Forces a check for updated
                                       releases and snapshots on remote
                                       repositories

However, you said:

I did do a 'mvn clean deploy', so the snapshot version should be somewhere in the maven central repository.

This is just not possible, your snapshot is going somewhere else. If I do a mvn clean deploy without configuring my personal repository I get:

Deployment failed: repository element was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter

To enable deployment, there is some configuration to be added to pom.xml, like for instance:

<distributionManagement>

    <!-- Publish versioned releases here -->
    <repository>
        <id>myrepo</id>
        <name>My releases</name>
        <url>http://nexus.mycompany.com/nexus/content/repositories/releases</url>
    </repository>

    <!-- Publish snapshots here -->
    <snapshotRepository>
        <id>myrepo</id>
        <name>my snapshots</name>
        <url>http://nexus.mycompany.com/nexus/content/repositories/snapshots</url>
    </snapshotRepository>

</distributionManagement>

<repositories>
    <repository>
        <id>myrepo</id>
        <name>My Public Repository</name>
        <url>http://nexus.mycompany.com/nexus/content/groups/public</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>
stivlo
  • 83,644
  • 31
  • 142
  • 199
  • Thanks for the help, see what I have in my settings.xml on my last edit to my question. Also, the library I am trying to refer to is. GroupID: me.soliveirajr Artifact: menta-container. Version: 0.9.9-SNAPSHOT. Can you find it anywhere in the maven repository? I can see it here... – chrisapotek Oct 10 '11 at 14:45
  • See EDIT2 for where I can see the snapshot. – chrisapotek Oct 10 '11 at 14:49
  • ok and when you do mvn deploy it's published fine? no error to see? in case try with mvn -e deploy and even mvn -X deploy if necessary – stivlo Oct 10 '11 at 15:06
  • It is published fine. I can find it through sonatype as you can see on my EDIT2. Sonatype do have a snapshot repository or am I missing something here? – chrisapotek Oct 10 '11 at 15:10
  • you could try to bump up the version to 0.9.9b to see if it gets published and update the receiving project pom as well with the new version – stivlo Oct 10 '11 at 15:19
24

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>
JohnPristine
  • 3,485
  • 5
  • 30
  • 49
  • 2
    can this be somehow added to the POM where the dependency is declared instead of in settings.xml? – Sergio Nov 07 '12 at 10:50
  • This saved the day. I've used `mvn -U` and other suggestions, but these didn't help with snapshot dependencies. – kubanczyk Jun 21 '18 at 11:45
19

Maven would try to download the snapshot automatically and indeed it does (as your error indicates). By default, Maven will look for newer snapshot versions once a day, but you can change that interval in your snapshot repository config (e.g. in settings.xml):

<updatePolicy>interval:5</updatePolicy>

This will make maven check every 5 minutes (if you build that often). Alternatively, you could use the -U or --update-snapshots option, to force the check manually.

However, it can't find the dependency. Could you post your repo settings and artifact config for the snapshot dependency?

Is the org.oop:oop:jar:0.9.9-SNAPSHOT artifact in your repository?

... so the snapshot version should be somewhere in the maven central repository.

No it isn't. I tried to look it up, but couldn't find it. Afaik, there's some staging mechanism, so maybe your settings are just wrong. But normally, as the others already said, you'd go and use your own repository manager like Artifactory or Nexus.

Thomas
  • 87,414
  • 12
  • 119
  • 157
1

Does that dependency exists in your repository? (in pom.xml or settings.xml)?

Looks like not. By the way, take a look at your config, just you are not using -o (offline). Also you can use -U to refresh snapshots.

ssedano
  • 8,322
  • 9
  • 60
  • 98
0

I hit the issue of snapshots not updating even when setting -U on the command line. For me the issue was my client was Maven 3 and the server was Maven 2, and in Maven 3 unique snapshots are no longer supported. We had to create a new repository with timestamped snapshots to support the 3.xx clients.

Ags1
  • 619
  • 1
  • 9
  • 18
0

You can either

  • use a parent project which builds all your snapshots, or
  • deploy your snapshots to your maven build server (nexus/archiva/..) using e.g., mvn:deploy
Johan Sjöberg
  • 47,929
  • 21
  • 130
  • 148
0

Let's clear up terminology a bit to make sure there is no misunderstanding.

"Maven Central" (http://search.maven.org/) is a global site where you only find releases. Central doesn't accept snapshots so deploying there should give you an error.

You probably mean your local/company wide maven proxy/cache. These can also be configured to reject snapshot versions. In case of Nexus, you can also define more complex rules. In my case, I had an issue there which gave no error during mvn deploy but I could see an error in the server's logs.

Try to follow the data: Enable debug (mvn -X) to see where Maven uploads the data. Then check the server to see whether the artifacts were really uploaded. Check the server's logs for errors.

Also note that snapshot dependencies are only refreshed once a day; so this won't work:

PC #1: mvn install -> Error missing dependency PC #2: mvn deploy PC #1: mvn install -> Dependency is still missing because of "update once per day" policy

Try mvn install -U to force Maven to refresh its cached metadata.

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
  • Check your local repo (`$HOME/.m2/repository/`): Does the folder hierarchy exist there? Is there a file `*metadata*.xml` somewhere? What does it contain? Do you see the download request on your Nexus server? – Aaron Digulla Oct 10 '11 at 15:05
  • I am not using my nexus server. I am using sonatype snapshot repository. Check my EDIT2. – chrisapotek Oct 10 '11 at 15:11
  • Find a way to get the logs from the Naxus instance running at Sonatype . Also read all my questions; they don't always depend on each other. One of them might lead you on the right track. – Aaron Digulla Oct 11 '11 at 11:36