maven插件 versions-maven-plugin maven-release-plugin

versions-maven-plugin插件批量修改版本号 https://blog.csdn.net/bugzeroman/article/details/88888912

mvn -f "pom.xml" versions:set -DoldVersion=* -DnewVersion=1.0.1 -DprocessAllModules=true -DallowSnapshots=true -DgenerateBackupPoms=true

mvn versions:revert

mvn versions:commit

使用maven-release-plugin控制版本发布 

简介

maven-release-plugin这个插件是maven官方提供的版本控制插件,其中最常用的三个操作
1.prepare
2.rollback
3.perform

发布前准备操作

1.添加plugin的依赖

2.配置scm即git项目的地址

3.添加本机与git仓库的ssh秘钥

版本发布操作

1.执行prepare

执行命令:
    单模块项目:mvn release:prepare -Darguments="-DskipTests"
    多模块项目:mvn release:prepare -DautoVersionSubmodules=true -Darguments="-DskipTests"
prepare命令做了哪些操作:
    1.检查项目是否有未提交的代码。
    2.检查项目是否有快照版本依赖。
    3.根据用户的输入将快照版本升级为发布版。
    4.将POM中的SCM信息更新为标签地址。
    5.基于修改后的POM执行Maven构建。
    6.提交POM变更。
    7.基于用户输入为代码打标签。
    8.将代码从发布版升级为新的快照版。
    9.提交POM变更。

2.执行perform

执行命令:
    mvn release:perform -DuseReleaseProfile=false
perform命令做了哪些操作(不够详细,待补充,先用起来):
    1.生成doc文档
    2.删除release.properties等发布过程文件

3.rollback(可选)

rollback是回滚操作rollback是回滚操作
注意生成的git标签和发布过程中的配置文件需要自行删除

POM.xml配置

<distributionManagement>
    <repository>
        <id>nexus-releases</id>
        <name>nexus-releases</name>
        <url>http://127.0.0.1/nexus/content/repositories/releases/</url>
    </repository>
    <snapshotRepository>
        <id>nexus-snapshots</id>
        <name>nexus-snapshots</name>
        <url>http://127.0.0.1/nexus/content/repositories/snapshots/</url>
    </snapshotRepository>
</distributionManagement>

<scm> 
        <!--release包需要放入的nexus或者其他maven release包的仓库url地址-->
        <url>http://xxxx/nexus/content/repositories/releases/</url>
        <!--connection, developerConnection: 都是连接字符串,其中后者是具有write权限的scm连接 -->
        <!--需要打包项目的git地址-->
        <developerConnection>scm:git:http://xxxx/project-name/project-name.git</developerConnection>
         <!--需要打包项目的git地址-->
        <connection>scm:git:http://xxx/project-name/project-name.git</connection>
        <!---->
        <tag>HEAD</tag>
    </scm>

例子:

<scm>
    <url>http://127.0.0.1/project_group/project-name</url>
    <connection>scm:git:[email protected]:project_group/project-name.git</connection>
    <developerConnection>scm:git:[email protected]:project_group/project-name.git</developerConnection>
    <tag>HEAD</tag>
</scm>


 <plugins>
            <!-- 发布插件 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-release-plugin</artifactId>
                <version>2.5.3</version>
                <configuration>
                    <!--git用户名-->
                    <username>[email protected]</username>
                    <!--git密码-->
                    <password>xxxx</password>
                    <!--mvn目标指令-->
                    <goals>-f pom.xml deploy</goals>
                </configuration>
            </plugin>
        </plugins>

发布了201 篇原创文章 · 获赞 5 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/mutourenoo/article/details/103117007