开发者

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

目录
  • maven打包时候修改包名称带上git版本号和打包时间
  • maven打包日常总结
  • 总结

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</artifac开发者_C入门tId>
                <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</generateGitProperandroidtiesFilename>
                    <!--".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</fowww.devze.comrceLongFormat>
                    </gitDescribe>
                </configuration>
            </plugin>
        </plugins>
    </build>

实际运行结果:

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

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包的包名,防止包冲突

<!--将第三方依赖javascript性jar包中的文件打包入jar中-->
      <plugin>
        <groupId>org.apache.maven.plugipythonns</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>

总结

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新开发

开发排行榜