解疑惑----maven中snapshot相关jar无法拉取问题

这段时间maven中经常不能拉取snapshot相关jar的问题一直困扰着,今天把相关解决方案整理下。
使用的是局域网中的Snaptype Nexus服务器的,maven的setting-main.xml相关配置如下:

<!-- <mirrors> ... </mirrors> -->

</profile>  
     <profile>
      <id>redstar-nexus</id>
      <repositories>
        <repository>
          <id>central</id>
          <url>http://nexus.******.com/nexus/content/groups/public/</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
          <updatePolicy>always</updatePolicy>

        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <id>central</id>
          <url>http://nexus.******.com/nexus/content/groups/public/</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
          <updatePolicy>always</updatePolicy>
        </pluginRepository>
      </pluginRepositories>
</profile>

<activeProfiles>
    <activeProfile>redstar-nexus</activeProfile>
</activeProfiles>

项目中有相关pom.xml引入的jar配置:

<!-- 引入父jar包 -->
<parent>
    <artifactId>parent</artifactId>
    <groupId>com.*****</groupId>
    <version>1.3.0.RELEASE</version>
</parent>

<!-- 引入服务的snapshot包-->
<dependencies>
  <dependency>
    <groupId>com.*******</groupId>
    <artifactId>show-tools</artifactId>
    <version>1.0.2-SNAPSHOT</version>
  </dependency>
</dependencies>

在使用项目的clean命令时,报错。因为默认是从maven的中央仓库中,更新jar报,但是报找不到parent中的引入jar包的。为了解决问题。在setting-main.xml文件中添加 <mirror>的相关配置:

<mirror>
            <id>private-mirror</id>
            <mirrorOf>*</mirrorOf>
            <name>private-mirror</name>
            <url>http://nexus.*****.com/nexus/content/groups/public/</url>
        </mirror>

这样只解决了仓库引入的问题。snapshot的jar引入依然没有解决。
但是mirror的配置,只对release有效,对于snapshot无效的。所以我们添加个对snapshot有效的:

<mirrors>
    <mirror>
        <id>private-mirror</id>
        <mirrorOf>*</mirrorOf>
        <name>private-mirror</name>
        <url>http://nexus.corp.rs.com/nexus/content/groups/public/</url>
    </mirror>

    <mirror>
        <id>private-snapshots</id>
        <url>http://nexus.****.com/nexus/content/repositories/snapshots/</url>
        <mirrorOf>public-snapshots</mirrorOf>
    </mirror>
</mirrors>

<profile>
    <id>public-snapshots</id>
    <repositories>  
        <repository>
            <id>nexus_snapshot_repository</id>
            <releases>
                <enabled>false</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
            <url>http://nexus.*****.com/nexus/content/repositories/snapshots/</url>
            <layout>default</layout>
        </repository>

    </repositories>

    <pluginRepositories>
        <pluginRepository>
          <id>central</id>
          <url>http://nexus.*****.com/nexus/content/groups/public/</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
          <updatePolicy>always</updatePolicy>
        </pluginRepository>
    </pluginRepositories>

</profile>

<activeProfiles>
    <activeProfile>public-snapshots</activeProfile>
</activeProfiles>

问题解决。这个配置的有些繁琐的,应该有更方便的方式。后续更新优化的。

snapshot的出现是解决release版本有变动要升级,在开发过程中造成频繁升级的问题的。maven会自动从仓库中检查引入服务的snapshot版本的最新版本,发现有要更新的时候进行下载的。默认每天一更新。通过updatePolicy控制(默认值是daily,表示Maven每天检查一次。其他可用的值包括:never-从不检查更新;always-每次构建都检查更新;interval:X-每隔X分钟检查一次更新(X为任意整数)

猜你喜欢

转载自blog.csdn.net/zcl111/article/details/80347330
今日推荐