iis服务器助手广告广告
返回顶部
首页 > 资讯 > 后端开发 > Python >maven打包时候修改包名称带上git版本号和打包时间方式
  • 486
分享到

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

maven打包maven修改包名称mavengit版本号maven打包时间 2023-05-14 14:05:56 486人浏览 独家记忆

Python 官方文档:入门教程 => 点击学习

摘要

目录Maven打包时候修改包名称带上git版本号和打包时间maven打包日常总结总结maven打包时候修改包名称带上git版本号和打包时间 使用 maven 插件 git-commi

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>

实际运行结果:

git.properties文件内容

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

maven打包日常总结

1、 将第三方依赖性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>

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

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

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

       <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>

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程网。

--结束END--

本文标题: maven打包时候修改包名称带上git版本号和打包时间方式

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

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

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

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

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

  • 微信公众号

  • 商务合作