Maven: Why is the -SNAPSHOT suffix missing from artifact file name?
Asked Answered
V

2

9

My maven artifact is deployed to a Nexus snapshot repository. There, it is stored in the correct directory, but its filenames have the following pattern:

mylibrary-1.0-20130213.125827-2.jar

However, Maven fails to download that snapshot. According to the error log, Maven seems to expect the following file name:

mylibrary-1.0-SNAPSHOT.jar

These are the repository settings in my pom:

<repositories>
    <repository>
        <id>mycompany-all</id>
        <url>https://servername/nexus/content/groups/mycompany/</url>
    </repository>
</repositories>

<distributionManagement>
    <repository>
        <id>mycompany-releases</id>
        <url>https://servername/nexus/content/repositories/releases/</url>
    </repository>
    <snapshotRepository>
        <id>mycompany-snapshots</id>
        <url>https://servername/nexus/content/repositories/snapshots/</url>
    </snapshotRepository>
</distributionManagement>

Note: the nexus group includes both the releases and snapshots repo.

I did not configure these repos in settings.xml - is that the problem? Or what else am I doing wrong?

Veracruz answered 14/2, 2013 at 7:40 Comment(1)
You say "Maven seems to expect...". Do you get an error when you follow my advice and reference mylibrary-1.0-20130213.125827-2.jar as mylibrary-1.0-SNAPSHOT?Beadle
V
7

I made it work by adding the repositories to the settings.xml like this:

<repositories>
    <repository>
        <id>mycompany-releases</id>
        <url>https://servername/nexus/content/repositories/releases/</url>
        <releases><enabled>true</enabled></releases>
        <snapshots><enabled>false</enabled></snapshots>
    </repository>
    <repository>
        <id>mycompany-snapshots</id>
        <url>https://servername/nexus/content/repositories/snapshots/</url>
        <releases><enabled>false</enabled></releases>
        <snapshots><enabled>true</enabled></snapshots>
    </repository>
</repositories>

Then, the SNAPSHOT jar files were downloaded just fine. I suspect that when Maven knows it deals with a snapshot repo, it tries both with and without uniqueVersion (see Duncan Jones' answer).

Note that in our case these blocks had to be duplicated as pluginRepositories because we have custom Maven plugins.

Veracruz answered 14/2, 2013 at 8:50 Comment(1)
Actually what is happening is that maven reads the maven-metadata.xml in the /com/mycompany/mylibrary/1.0-SNAPSHOT folder. This xml tells maven what the latest timestamp and build number it should use. Maven then turns around and constructs the request for that specific unique version. If Maven can't find the maven-metadata.xml, as would be the case if you didn't have a snapshot repository, it will make a hail-mary request for the -SNAPSHOT version to see if it's there.Fledge
B
15

The pattern you posted (mylibrary-1.0-20130213.125827-2.jar) is a unique snapshot version. Maven 3 forces you to use this type of artifact naming, but in Maven 2 it can be prevented with a statement such as:

<distributionManagement>
  ...
  <snapshotRepository>
    ...
    <uniqueVersion>false</uniqueVersion>
  </snapshotRepository>
  ...
</distributionManagement>

To use a specific snapshot in your project, declare it as:

<dependency>
  <groupId>com.foo</groupId>
  <artifactId>mylibrary</artifactId>
  <version>1.0-20130213.125827-2</version>
</dependency>

To use the latest known snapshot, declare it "old-style":

<dependency>
  <groupId>com.foo</groupId>
  <artifactId>mylibrary</artifactId>
  <version>1.0-SNAPSHOT</version>
</dependency>

You may find the answer to this similar question helpful as well.

Beadle answered 14/2, 2013 at 8:7 Comment(0)
V
7

I made it work by adding the repositories to the settings.xml like this:

<repositories>
    <repository>
        <id>mycompany-releases</id>
        <url>https://servername/nexus/content/repositories/releases/</url>
        <releases><enabled>true</enabled></releases>
        <snapshots><enabled>false</enabled></snapshots>
    </repository>
    <repository>
        <id>mycompany-snapshots</id>
        <url>https://servername/nexus/content/repositories/snapshots/</url>
        <releases><enabled>false</enabled></releases>
        <snapshots><enabled>true</enabled></snapshots>
    </repository>
</repositories>

Then, the SNAPSHOT jar files were downloaded just fine. I suspect that when Maven knows it deals with a snapshot repo, it tries both with and without uniqueVersion (see Duncan Jones' answer).

Note that in our case these blocks had to be duplicated as pluginRepositories because we have custom Maven plugins.

Veracruz answered 14/2, 2013 at 8:50 Comment(1)
Actually what is happening is that maven reads the maven-metadata.xml in the /com/mycompany/mylibrary/1.0-SNAPSHOT folder. This xml tells maven what the latest timestamp and build number it should use. Maven then turns around and constructs the request for that specific unique version. If Maven can't find the maven-metadata.xml, as would be the case if you didn't have a snapshot repository, it will make a hail-mary request for the -SNAPSHOT version to see if it's there.Fledge

© 2022 - 2024 — McMap. All rights reserved.