iis服务器助手广告广告
返回顶部
首页 > 资讯 > 精选 >maven打包时候修改包名称带上git版本号和打包时间的方法是什么
  • 464
分享到

maven打包时候修改包名称带上git版本号和打包时间的方法是什么

2023-07-05 23:07:04 464人浏览 独家记忆
摘要

本文小编为大家详细介绍“Maven打包时候修改包名称带上git版本号和打包时间的方法是什么”,内容详细,步骤清晰,细节处理妥当,希望这篇“maven打包时候修改包名称带上git版本号和打包时间的方法是什么”文章能帮助大家解决疑惑,下面跟着小

本文小编为大家详细介绍“Maven打包时候修改包名称带上git版本号和打包时间的方法是什么”,内容详细,步骤清晰,细节处理妥当,希望这篇“maven打包时候修改包名称带上git版本号和打包时间的方法是什么”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知识吧。

maven打包时候修改包名称带上git版本号和打包时间

使用 maven 插件 git-commit-id-plugin 可以获取项目的git信息,然后,使用这个信息,修改打包的名称,使其带上git版本号以及打包时间。

<build>        <finalName>${artifactId}-${git.commit.id.abbrev}-${git.build.time}</finalName>        <plugins>            <plugin>                <groupId>pl.project13.maven</groupId>                <artifactId>git-commit-id-plugin</artifactId>                <version>2.1.5</version>                <executions>                    <execution>                        <id>get-the-git-infos</id>                        <!-- 默认绑定阶段initialize -->                        <phase>initialize</phase>                        <Goals>                            <goal>revision</goal>                        </goals>                    </execution>                </executions>                <configuration>                    <!--日期格式;默认值:dd.MM.yyyy '@' HH:mm:ss z;-->                    <dateFORMat>yyyy-MM-dd_HH-mm-ss</dateFormat>                    <!--,构建过程中,是否打印详细信息;默认值:false;-->                    <verbose>true</verbose>                    <!-- ".git"文件路径;默认值:${project.basedir}/.git; ${project.basedir}:项目根目录,即包含pom.xml文件的目录-->                    <dotGitDirectory>${project.basedir}/../../../.git</dotGitDirectory>                    <!--若项目打包类型为pom,是否取消构建;默认值:true;-->                    <skipPoms>false</skipPoms>                    <!--是否生成"git.properties"文件;默认值:false;-->                    <generateGitPropertiesFile>true</generateGitPropertiesFile>                    <!--指定"git.properties"文件的存放路径(相对于${project.basedir}的一个路径);-->                    <generateGitPropertiesFilename>/src/main/resources/git.properties</generateGitPropertiesFilename>                    <!--".git"文件夹未找到时,构建是否失败;若设置true,则构建失败;若设置false,则跳过执行该目标;默认值:true;-->                    <failOnNoGitDirectory>true</failOnNoGitDirectory>                     <!--git描述配置,可选;由JGit提供实现;-->                    <gitDescribe>                        <!--是否生成描述属性-->                        <skip>false</skip>                        <!--提交操作未发现tag时,仅打印提交操作ID,-->                        <always>false</always>                        <!--提交操作ID显式字符长度,最大值为:40;默认值:7; 0代表特殊意义;后面有解释;-->                        <abbrev>7</abbrev>                        <!--构建触发时,代码有修改时(即"dirty state"),添加指定后缀;默认值:"";-->                        <dirty>-dirty</dirty>                        <!--always print using the "tag-commits_from_tag-g_commit_id-maybe_dirty" format, even if "on" a tag.                            The distance will always be 0 if you're "on" the tag.  -->                        <forceLongFormat>false</forceLongFormat>                    </gitDescribe>                </configuration>            </plugin>        </plugins>    </build>

实际运行结果:

maven打包时候修改包名称带上git版本号和打包时间的方法是什么

git.properties文件内容

#Generated by Git-Commit-Id-Plugin#Fri Nov 12 15:06:14 CST 2021git.commit.id.abbrev=ff60f80git.commit.user.email=xxx@163.comgit.commit.message.full=git提交说明git.commit.id=ff60f8091627e53891fc15bdccad93115f8623c9git.commit.message.short=简要说明git.commit.user.name=abcgit.build.user.name=efggit.commit.id.describe=xxxxgit.build.user.email=xxx@163.comgit.branch=xxx-devgit.commit.time=2011-11-09_14-00-40git.build.time=2011-11-12_15-06-14git.remote.origin.url=Http\://1.1.1.1\:1/group/xxx.git

maven打包日常总结

将第三方依赖性jar包中的文件打包入jar中,打包时修改引入jar包的包名,防止包冲突

 <!--将第三方依赖性jar包中的文件打包入jar中-->            <plugin>                <groupId>org.apache.maven.plugins</groupId>                <artifactId>maven-shade-plugin</artifactId>                <!-- 打包失败可能是版本太低,提高版本 -->                <version>3.1.0</version>                <executions>                    <execution>                        <phase>package</phase>                        <goals>                            <goal>shade</goal>                        </goals>                        <configuration>                            <!-- 打包时修改引入jar包的包名,防止包冲突 -->                            <relocations>                                <relocation>                                    <pattern>org.apache.http</pattern>                                    <shadedPattern>shaded.org.apache.http</shadedPattern>                                    <!--<excludes>-->                                    <!--<exclude>org.codehaus.plexus.util.xml.Xpp3Dom</exclude>-->                                    <!--<exclude>org.codehaus.plexus.util.xml.pull.*</exclude>-->                                    <!--</excludes>-->                                </relocation>                            </relocations>                             <filters>                                <filter>                                    <artifact>*:*</artifact>                                    <excludes>                                        <exclude>META-INF/*.SF</exclude>                                        <exclude>META-INF/*.DSA</exclude>                                        <exclude>META-INF/*.RSA</exclude>                                    </excludes>                                </filter>                            </filters>                        </configuration>                    </execution>                </executions>            </plugin>

阻止第三方jar包被打入执行包

        <dependency>            <groupId>org.apache.hadoop</groupId>            <artifactId>hadoop-client</artifactId>            <version>2.7.2</version>            <!-- 阻止第三方jar包被打入执行包 -->            <scope>provided</scope>        </dependency>

打包时不包含该包下的部分子包

       <dependency>            <groupId>org.elasticsearch.client</groupId>            <artifactId>elasticsearch-rest-high-level-client</artifactId>            <version>6.3.2</version>            <!-- 不包含org.apache.httpcomponents包 -->            <exclusions>                <exclusion>                <groupId>org.apache.httpcomponents</groupId>                <artifactId>httpcore</artifactId>                </exclusion>            </exclusions>        </dependency>

读到这里,这篇“maven打包时候修改包名称带上git版本号和打包时间的方法是什么”文章已经介绍完毕,想要掌握这篇文章的知识点还需要大家自己动手实践使用过才能领会,如果想了解更多相关内容的文章,欢迎关注编程网精选频道。

--结束END--

本文标题: maven打包时候修改包名称带上git版本号和打包时间的方法是什么

本文链接: https://www.lsjlt.com/news/355723.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作