maven版本控制方案

一.maven版本管理现状

  • 很多工程在生产发布的时候,都是直接引用Snapshot依赖包,如此snapshot包会直接在生产环境中使用。
  • 修改接口后版本号没有升级,导致版本回滚风险很大.
  • 有时候一个需求测试完成后,发布到准生产以及生产的时候因为依赖的包发生了改变(新需求导致),使准生产或生产环境产生编译或运行时出错。

二.maven版本管理解决方案

1.发布非开发环境(测试/准生产/demo/生产)都引用release依赖包

  • 这样可以保证测试,准生产,生产使用的是同一个依赖包。
  • 发布开发环境使用-Denforcer.skip=true参数跳过检查。
  • 非开发环境jenkins发布时使用enforcer插件检查项目中是否引用了Snapshot.配置如下:
<plugin>                
    <groupId>org.apache.maven.plugins</groupId>  
    <artifactId>maven-enforcer-plugin</artifactId>  
    <version>1.4.1</version>  
    <executions>  
        <execution>  
            <id>enforce-versions</id>  
            <goals>  
                <goal>enforce</goal>  
            </goals>  
            <configuration>  
              <rules>  
                <requireReleaseDeps>
                    <message>No Snapshots Allowed!</message>
                </requireReleaseDeps>
              </rules>  
            </configuration>  
          </execution>  
        </executions>  
    </plugin>  

2.保证release包不会重复发布(必要性是:如果release可以重复发布,那和现在使用snapshot导致的问题一样)。

  • 切换maven仓库,把原来使用的artifactory迁移动nexus上,新的nexus地址为http://172.16.21.221:8081/nexus/.
  • 配置nexus中release库不允许重复发布,即每一个版本号只能发布一次。如版本号为3.0.0,第一次发布它的时候是成功的,第二次发布会报错,必须修改版本号才能发布。
  • 版本号什么时候升级由开发人员自己控制。

3.新maven配置

  • settings.xml配置如下:
<?xml version="1.0" encoding="UTF-8"?>
<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd" xmlns="http://maven.apache.org/SETTINGS/1.1.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

  <localRepository>/workspace/mvn/repo-nenux</localRepository>

  <servers>
    <server>
      <username>deployment</username>
      <password>deployment123</password>
      <id>central</id>
    </server>
    <server>
      <username>deployment</username>
      <password>deployment123</password>
      <id>snapshots</id>
    </server>
    <server>
      <username>deployment</username>
      <password>deployment123</password>
      <id>nexus</id>
    </server> 
  </servers>
  <profiles>
    <profile>
      <repositories>
        <repository>
          <snapshots />
          <id>nexus</id>
          <name>libs-nexus</name>
          <url>http://172.16.21.221:8081/nexus/content/groups/public/</url>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <snapshots />
          <id>nexus</id>
          <name>plugins-nexus</name>
          <url>http://172.16.21.221:8081/nexus/content/groups/public/</url>
        </pluginRepository>
      </pluginRepositories>
      <id>nexus</id>
    </profile>
  </profiles>

  <activeProfiles>
    <activeProfile>nexus</activeProfile>
  </activeProfiles>
</settings>
  • 发布的pom配置如下:
<distributionManagement>
        <repository>
            <id>central</id>
            <name>Artifactory Release Repository</name>
            <url>http://172.16.21.221:8081/nexus/content/repositories/releases/</url>
        </repository>
        <snapshotRepository>
            <id>snapshots</id>
            <name>Artifactory Snapshot Repository</name>
            <url>http://172.16.21.221:8081/nexus/content/repositories/snapshots/</url>
        </snapshotRepository>
    </distributionManagement>

4.maven 阿里云的配置


  <profile>
      <repositories>
        <repository>
          <snapshots />
          <id>aliyun</id>
          <name>libs-nexus</name>
               <url>http:/maven.aliyun.com/nexus/content/groups/public/</url>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <snapshots />
          <id>aliyun</id>
          <name>plugins-nexus</name>
          <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
        </pluginRepository>
      </pluginRepositories>
      <id>aliyun</id>
    </profile>

鸣谢

本人摘录自飞马大宗-贸易部*俊中

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值