Maven2中snapshot快照库的使用

[转载声明] 转载时必须标注:本文来源于铁木箱子的博客http://www.mzone.cc
[本文地址] 本文永久地址是: http://www.mzone.cc/article/654.html

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

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

      2、maven中snapshot快照库和release发布库的区别和作用

      另外,今天在使用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快照库是没有生效导致的,如此配置即可解决

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值