maven release 插件使用

关于release与snapshot的区别这里不再赘述,maven项目在生产环境部署的时候一定是需要打release包的。

maven-release-plugin 可用于构建release版本项目,实现自动打tag、递增版本号、分发release版本jar包至仓库。

pom.xml配置:

<!--git 远程仓库配置-->
<scm>
        <connection>scm:git:http://项目git地址</connection>
        <url>项目git地址(不加'.git后缀')</url>
        <developerConnection>scm:项目git地址</developerConnection>
 </scm>

 <!--构建配置-->
 <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-release-plugin</artifactId>
                <version>2.5.3</version>
                <configuration>
                    <tagNameFormat>v@{project.version}</tagNameFormat>
                    <autoVersionSubmodules>true</autoVersionSubmodules>
                </configuration>
            </plugin>
        </plugins>
    </build>
   
    <!--分发配置-->
    <distributionManagement>
        <repository>
            <id>deploymentRepo</id>
            <name>releases</name>
            <url>http://somehost/repository/maven-releases/</url>
            <uniqueVersion>true</uniqueVersion>
        </repository>
        <snapshotRepository>
            <id>deploymentRepo</id>
            <name>snapshots</name>
            <url>http://somehost/repository/maven-snapshots/</url>
            <uniqueVersion>true</uniqueVersion>
        </snapshotRepository>
    </distributionManagement>

由于会将构建的包分发到仓库,需要在maven的配置文件setting.xml下加入权限配置:

    <server>
      <id>your id</id>
      <username>your username</username>
      <password>your pass</password>
    </server>

这里最关键的一点是scm节点配置,无论项目是使用git、svn或是其他版本控制工具,都可以在这里配置,详细的配置可参考scms-overview

下面是一个项目配置示例:

   <scm>
        <connection>scm:git:http://git-local.bnz.com/srv/bnz-ep.git</connection>
        <url>http://git-local.bnz.com/srv/bnz-ep</url>
        <developerConnection>scm:git:http://git-local.bnz.com/srv/bnz-ep.git</developerConnection>
    </scm>

如果需要跳过单元测试,可以加入参数 -Darguments="-DskipTests",直接使用-Dmaven.test.skip=true无效的。

在执行mvn release:perform时默认会生成api文档,如果默写注释不符合规范的话会造成构建失败,可以加参数-DuseReleaseProfile=false取消构建api文档,或则需要根据规范书写注释。

mvn release:prepare
mvn release:perform

如果在构建过程中出现错误,rollback回滚即可

mvn release:rollback
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 136,435评论 19 139
  • Spring Boot 参考指南 介绍 转载自:https://www.gitbook.com/book/qbgb...
    毛宇鹏阅读 47,251评论 6 342
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 178,161评论 25 709
  • |-1-更新内容[6.从仓库解析依赖的机制(重要)] 1Maven仓库作用 仓库用来存储所有项目使用到构件,在ma...
    zlcook阅读 6,430评论 0 25
  • 时下,共享经济成为“新经济盛宴”,不经意间,搞经济的不谈共享经济就感觉很“low”;搞企业的不跟共享挂钩就感觉“o...
    白话劳动法阅读 520评论 0 1

友情链接更多精彩内容