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

纵然是瞬间 提交于 2019-11-29 14:05:26

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/14869962/maven-why-is-the-snapshot-suffix-missing-from-artifact-file-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!