[本文地址] 本文永久地址是: http://www.mzone.cc/article/654.html
之前有过几篇文章介绍了mavven中release和snapshot库的作用,如下(不太了解的可以参考看一下):
1、maven2中snapshot快照库和release发布库的应用
2、maven中snapshot快照库和release发布库的区别和作用
另外,今天在使用snapshot快照库时遇到一个问题,我一个构件的发布配置如下(在构件的pom文件中):
<modelVersion>4.0.0 </modelVersion> <groupId>cc.mzone </groupId> <artifactId>workflow </artifactId> <version>0.1-SNAPSHOT </version> <packaging>jar </packaging> <distributionManagement> <repository> <id>kt </id> <url>http://192.168.1.112/nexus/content/repositories/kt </url> </repository> <snapshotRepository> <id>kt-snapshot </id> <url>http://192.168.1.112/nexus/content/repositories/kt-snapshot </url> <uniqueVersion>true </uniqueVersion> </snapshotRepository> </distributionManagement>
这个是构件的发布配置,其中snapshot快照库中使用了uniqueVersion为true,这个表明每次发布都会在服务器上留下一个新版本(加上时间后缀的版本)。这个true和false不影响快照库,只是是否节省服务器空间的问题。在通过mvn deploy发布到服务器后,在依赖该构件的项目的pom文件中写上依赖:
<dependency> <groupId>cc.mzone </groupId> <artifactId>workflow </artifactId> <version>0.1-SNAPSHOT </version> </dependency>
然后在该项目中执行:mvn eclipse:eclipse进行其依赖构件的下载,结果却发现提示如下:
[WARNING ] An error occurred during dependency resolution. Failed to retrieve cc.mzone:workflow- 0.1-SNAPSHOT Caused by: Unable to download the artifact from any repository Try downloading the file manually from the project website.
刚开始不太清楚原因,经过查证比对,发现是因为项目没有开启snapshot快照库的缘故!知道了原因,解决就好办了,有两种方法可以解决:
1、第一种方法是在项目的pom文件中进行配置,如下:
<repositories> <repository> <id>cc-mzone-nexus </id> <name>MZONE </name> <url>http://192.168.1.112/nexus/content/groups/public/ </url> <snapshots> <enabled>true </enabled> <updatePolicy>interval:5 </updatePolicy> </snapshots> </repository> </repositories>
2、第二种方法是在maven的配置文件(conf/settings.xml)中进行配置,如下:
<profiles> <profile> <id>cc-mzone-profile </id> <repositories> <repository> <id>cc-mzone-nexus </id> <name>MZONE </name> <url>http://192.168.1.112/nexus/content/groups/public/ </url> <releases> <enabled>true </enabled> </releases> <snapshots> <enabled>true </enabled> <updatePolicy>interval:10 </updatePolicy> </snapshots> </repository> </repositories> </profile> </profiles> <activeProfiles> <activeProfile>cc-mzone-profile </activeProfile> </activeProfiles>
以上两种方式都是打开snapshot快照库,允许快照库生效(重要就是snapshot中enabled要设置为true),第一种是项目级别的,第二种是全局的。出现的问题当然主要还是默认snapshot快照库是没有生效导致的,如此配置即可解决