Maven: Why is the -SNAPSHOT suffix missing from ar

2020-02-26 08:55发布

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?

2条回答
Ridiculous、
2楼-- · 2020-02-26 09:31

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.

查看更多
我想做一个坏孩纸
3楼-- · 2020-02-26 09:42

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.

查看更多
登录 后发表回答