Maven构建生成的文件加上commit-id
【问题来源】构建生成的jar中需要有一个SHA码,确定是哪一个版本。
【解决方案】
pom.xml里调用git-commit-id-plugin
<plugin> <groupId>pl.project13.maven</groupId> <artifactId>git-commit-id-plugin</artifactId> <version>3.0.0</version> <executions> <execution> <id>get-the-git-infos</id> <goals> <goal>revision</goal> </goals> <phase>validate</phase> </execution> </executions> <configuration> <dotGitDirectory>${project.basedir}/.git</dotGitDirectory> <prefix>git</prefix> <verbose>false</verbose> <generateGitPropertiesFile>true</generateGitPropertiesFile> <generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties</generateGitPropertiesFilename> <format>json</format> <gitDescribe> <skip>false</skip> <always>false</always> <dirty>-dirty</dirty> </gitDescribe> </configuration> </plugin>
同时修改build部分,增加${git.commit.id.abbrev}
<build> <finalName>VIMGW-${project.version}-${git.commit.id.abbrev}</finalName> <plugin>
....
<groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>2.3</version> <executions> <execution> <id>vimgw-main-jar-single</id> <phase>package</phase> <goals> <goal>jar</goal> </goals> <configuration> <finalName>${project.artifactId}-${project.version}-${git.commit.id.abbrev}</finalName> <archive>