【问题标题】:Maven: Why is the -SNAPSHOT suffix missing from artifact file name?Maven:为什么工件文件名中缺少 -SNAPSHOT 后缀?
【发布时间】:2013-02-14 07:40:19
【问题描述】:

我的 Maven 工件已部署到 Nexus 快照存储库。在那里,它存储在正确的目录中,但其文件名具有以下模式:

mylibrary-1.0-20130213.125827-2.jar

但是,Maven 无法下载该快照。根据错误日志,Maven 似乎期望以下文件名:

mylibrary-1.0-SNAPSHOT.jar

这些是我的 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>

注意:nexus 组包括 releasessnapshots 存储库。

我没有在settings.xml 中配置这些存储库 - 是这个问题吗?还是我做错了什么?

【问题讨论】:

  • 你说“Maven 似乎期望...”。当您遵循我的建议并将mylibrary-1.0-20130213.125827-2.jar 引用为mylibrary-1.0-SNAPSHOT 时,您是否收到错误消息?

标签: maven nexus snapshot artifact


【解决方案1】:

您发布的模式 (mylibrary-1.0-20130213.125827-2.jar) 是一个独特的快照版本。 Maven 3 强制您使用这种类型的工件命名,但在 Maven 2 中可以通过以下语句来防止它:

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

要在项目中使用特定快照,请将其声明为:

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

要使用最新的已知快照,请将其声明为“旧式”:

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

您可能会发现这个similar question 的答案也很有帮助。

【讨论】:

    【解决方案2】:

    我通过将存储库添加到 settings.xml 使其工作,如下所示:

    <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>
    

    然后,SNAPSHOT jar 文件就下载好了。我怀疑当 Maven 知道它处理快照存储库时,它会尝试使用和不使用 uniqueVersion(请参阅 Duncan Jones 的回答)。

    请注意,在我们的例子中,这些块必须复制为 pluginRepositories,因为我们有自定义 Maven 插件。

    【讨论】:

    • 实际上发生的是maven读取/com/mycompany/mylibrary/1.0-SNAPSHOT文件夹中的maven-metadata.xml。这个 xml 告诉 maven 它应该使用什么最新的时间戳和内部版本号。然后,Maven 转身为那个特定的唯一版本构造请求。如果 Maven 找不到 maven-metadata.xml(如果您没有快照存储库就是这种情况),它将向 -SNAPSHOT 版本发出 hail-mary 请求以查看它是否存在。
    猜你喜欢
    • 2019-07-20
    • 2014-01-04
    • 2013-07-12
    • 2013-06-09
    • 2021-08-13
    • 1970-01-01
    • 1970-01-01
    • 2015-05-08
    • 1970-01-01
    相关资源
    最近更新 更多