【问题标题】:How to download SNAPSHOT version from maven SNAPSHOT repository?如何从 maven SNAPSHOT 存储库下载 SNAPSHOT 版本?
【发布时间】:2011-12-04 15:29:05
【问题描述】:

所以我有一个项目,我定期发布到 maven 没有问题。我现在想提供这个项目的 SNAPSHOT 版本。所以我做'mvn clean deploy'。一切正常,如下所示:

[INFO] 从 sonatype-nexus-snapshots 检索以前的内部版本号 上传:https://oss.sonatype.org/content/repositories/snapshots/me/soliveirajr/menta-regex/0.9.6-SNAPSHOT/menta-regex-0.9.6-20111010.153035-2.jar 5K 上传 (menta-regex-0.9.6-20111010.153035-2.jar)

我去我的 sonatype 管理器,我可以找到快照:

但是现在,当我尝试将此快照用作对其他项目的依赖项时在另一台机器上我得到:

<dependency>
  <groupId>me.soliveirajr</groupId>
  <artifactId>menta-regex</artifactId>
  <version>0.9.6-SNAPSHOT</version>
</dependency>

缺失:

1) me.soliveirajr:menta-regex:jar:0.9.6-SNAPSHOT

尝试从项目网站手动下载文件。

然后,使用以下命令安装它: mvn install:install-file -DgroupId=me.soliveirajr -DartifactId=menta-regex -Dversion=0.9.6-SNAPSHOT -Dpackaging=jar -Dfile=/path/to/file

或者,如果您托管自己的存储库,则可以在那里部署文件: mvn deploy:deploy-file -DgroupId=me.soliveirajr -DartifactId=menta-regex -Dversion=0.9.6-SNAPSHOT -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id ]

那么如何强制 maven 将 SNAPSHOT 版本下载到我的本地 (.m2) 存储库?

【问题讨论】:

    标签: java maven-2 maven snapshot


    【解决方案1】:

    只需将其添加到您的 ~/.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>
    

    【讨论】:

    • 不错的例子,给任何读者:请注意,如果你正在寻找 JaCoCo 的最新快照,不要犯和我一样的错误,并复制这个例子。因为它是一个插件,它们有不同的 repo。看到这个答案:stackoverflow.com/a/46682942/1546042
    【解决方案2】:

    为了完整起见,我想补充一点,也可以通过修改一个项目的pom.xml,简单地添加

     <repositories>
        <repository>
          <id>oss.sonatype.org-snapshot</id>
          <url>https://oss.sonatype.org/content/repositories/snapshots</url>
          <releases>
            <enabled>false</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </repository>
      </repositories>
    

    到您的存储库列表。

    在我看来,这比修改~/.m2/settings.xml 更好。 pom.xml 文件也将通过 Git 提供给其他项目参与者,并允许他们下载快照。

    来源:this answer

    【讨论】:

    • 这非常有帮助。对于那些没有&lt;repositories&gt; 部分的小提示,您需要在这段代码的开头添加一个标签,它与属性和依赖项处于同一级别。
    • 谢谢,添加了缺少的开始标签!
    • 这是如何使用常规依赖和插件的 SNAPSHOT 工件的示例github.com/checkstyle/checkstyle/wiki/…
    【解决方案3】:

    【讨论】:

    • 快照URL,我用什么?在示例中,他有:http://snapshots?我可能正在寻找 nexus 快照存储库。
    • 你需要为你想要的所有快照库配置它,但它看起来有你想要的——很酷:)
    【解决方案4】:

    您可以在存储库配置 (~/.m2/settings.xml) 中启用快照:

    <settings>
        <profiles>
            <profile>
              <repositories>
                <repository>
                  <snapshots>                  <<<<<<<<<<<
                    <enabled>true</enabled>    << ADD THIS
                  </snapshots>                 <<<<<<<<<<<
      . . .
    </settings>
    

    查看maven.apache.org/settings.html#Repositories了解更多属性。

    【讨论】:

      猜你喜欢
      • 2016-04-19
      • 2017-02-22
      • 2019-09-27
      • 1970-01-01
      • 2019-09-28
      • 1970-01-01
      • 2018-05-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多