Maven: jar包名中自动添加git commit id

Maven: jar包名自动添加git commit id


  • 插件名:maven-git-commit-id-plugin
  • pom.xml plugin配置样例
......
  <plugin>
    <groupId>pl.project13.mavengroupId>
    <artifactId>git-commit-id-pluginartifactId>
    <version>2.2.4version>
    <executions>
      <execution>
        <id>get-the-git-infosid>
        <goals>
          <goal>revisiongoal>
        goals>
      execution>
    executions>
    <configuration>
      
      <injectAllReactorProjects>trueinjectAllReactorProjects>
      <dateFormat>yyyy.MM.dd HH:mm:ssdateFormat>
      <verbose>trueverbose>
      
      <generateGitPropertiesFile>truegenerateGitPropertiesFile>
      
      <gitDescribe>
        
        <skip>falseskip>
        
        <always>falsealways>
        
        <abbrev>7abbrev>
        
        <dirty>-dirtydirty>
        
        <forceLongFormat>falseforceLongFormat>
      gitDescribe>
    configuration>
plugin>
......
  • pom.xml jar包名配置样例(结合maven-shade-plugin)
    • 同时会在target/classes下生成git.properties文件
......
      <plugin>
        <groupId>org.apache.maven.pluginsgroupId>
        <artifactId>maven-shade-pluginartifactId>
        <version>2.4.3version>
        <executions>
          <execution>
            <phase>packagephase>
            <goals>
              <goal>shadegoal>
            goals>
            <configuration>
              <artifactSet>
                <includes>
                  <include>*:*include>
                includes>
              artifactSet>
              
              <outputFile>
                ${project.build.directory}/${project.artifactId}-${git.commit.id.abbrev}.jar
              outputFile>
            configuration>
          execution>
        executions>
      plugin>
......

你可能感兴趣的:(个人总结,工具)