zoukankan      html  css  js  c++  java
  • [转]Maven2中snapshot快照库的使用

    Post by 铁木箱子 in Java技术杂谈 on 2011-10-28 12:12.

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

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

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

          2、

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

  • 相关阅读:
    小学教师资格考试——综合素质——材料分析
    小学教师资格考试——综合素质——教师基本能力
    牛客网暑假训练第一场——J Different Integers(莫队算法 & 树状数组)
    牛客网暑假训练第二场——A run(递推&前缀和)
    CSU
    ZOJ
    CSU
    CSU
    HDU
    Hrbust-2090 背包(最小不可构造数)
  • 原文地址:https://www.cnblogs.com/enjoycode/p/5006381.html
Copyright © 2011-2022 走看看