打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Maven2中snapshot快照库的使用 | 铁木箱子

      之前有过几篇文章介绍了mavven中release和snapshot库的作用,如下(不太了解的可以参考看一下):

      1、maven2中snapshot快照库和release发布库的应用

      2、

      另外,今天在使用snapshot快照库时遇到一个问题,我一个构件的发布配置如下(在构件的pom文件中):

  1. <modelVersion>4.0.0</modelVersion>
  2. <groupId>cc.mzone</groupId>
  3. <artifactId>workflow</artifactId>
  4. <version>0.1-SNAPSHOT</version>
  5. <packaging>jar</packaging>
  6. <distributionManagement>
  7. <repository>
  8. <id>kt</id>
  9. <url>http://192.168.1.112/nexus/content/repositories/kt</url>
  10. </repository>
  11. <snapshotRepository>
  12. <id>kt-snapshot</id>
  13. <url>http://192.168.1.112/nexus/content/repositories/kt-snapshot</url>
  14. <uniqueVersion>true</uniqueVersion>
  15. </snapshotRepository>
  16. </distributionManagement>

      这个是构件的发布配置,其中snapshot快照库中使用了uniqueVersion为true,这个表明每次发布都会在服务器上留下一个新版本(加上时间后缀的版本)。这个true和false不影响快照库,只是是否节省服务器空间的问题。在通过mvn deploy发布到服务器后,在依赖该构件的项目的pom文件中写上依赖:

  1. <dependency>
  2. <groupId>cc.mzone</groupId>
  3. <artifactId>workflow</artifactId>
  4. <version>0.1-SNAPSHOT</version>
  5. </dependency>

      然后在该项目中执行:mvn eclipse:eclipse进行其依赖构件的下载,结果却发现提示如下:

  1. [WARNING] An error occurred during dependency resolution.
  2. Failed to retrieve cc.mzone:workflow-0.1-SNAPSHOT
  3. Caused by: Unable to download the artifact from any repository
  4. Try downloading the file manually from the project website.

      刚开始不太清楚原因,经过查证比对,发现是因为项目没有开启snapshot快照库的缘故!知道了原因,解决就好办了,有两种方法可以解决:

1、第一种方法是在项目的pom文件中进行配置,如下

  1. <repositories>
  2. <repository>
  3. <id>cc-mzone-nexus</id>
  4. <name>MZONE</name>
  5. <url>http://192.168.1.112/nexus/content/groups/public/</url>
  6. <snapshots>
  7. <enabled>true</enabled>
  8. <updatePolicy>interval:5</updatePolicy>
  9. </snapshots>
  10. </repository>
  11. </repositories>

2、第二种方法是在maven的配置文件(conf/settings.xml)中进行配置,如下

  1. <profiles>
  2. <profile>
  3. <id>cc-mzone-profile</id>
  4. <repositories>
  5. <repository>
  6. <id>cc-mzone-nexus</id>
  7. <name>MZONE</name>
  8. <url>http://192.168.1.112/nexus/content/groups/public/</url>
  9. <releases>
  10. <enabled>true</enabled>
  11. </releases>
  12. <snapshots>
  13. <enabled>true</enabled>
  14. <updatePolicy>interval:10</updatePolicy>
  15. </snapshots>
  16. </repository>
  17. </repositories>
  18. </profile>
  19. </profiles>
  20. <activeProfiles>
  21. <activeProfile>cc-mzone-profile</activeProfile>
  22. </activeProfiles>

      以上两种方式都是打开snapshot快照库,允许快照库生效(重要就是snapshot中enabled要设置为true),第一种是项目级别的,第二种是全局的。出现的问题当然主要还是默认snapshot快照库是没有生效导致的,如此配置即可解决问题!

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
我的Maven之旅(5)-建立你自己的本地仓库(Maven仓库管理-Nexus)
关于Maven
使用MyEclipse构建MAVEN项目
Maven使用nexus配置,SNAPSHOT版本介绍及发布jar到nexus
Maven多项目依赖配置
Maven的仓库和settings.xml配置文件
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服