找到了一個方便我使用的解決方案groovy maven插件。
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>groovy-maven-plugin</artifactId>
<version>2.0</version>
<executions>
<execution>
<phase>process-classes</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<defaults>
<name>Xenu</name>
</defaults>
<source>
String fileContents = new File("${project.basedir}/../include/version.h").getText('UTF-8')
matcher = (fileContents =~ /(?s).*MAJOR ([0-9]+).*?/)
String major_version = matcher.getAt(0).getAt(1)
matcher = (fileContents =~ /(?s).*MINOR ([0-9]+).*?/)
String minor_version = matcher.getAt(0).getAt(1)
matcher = (fileContents =~ /(?s).*PATCH ([0-9]+).*?/)
String patch_version = matcher.getAt(0).getAt(1)
String version = String.format('%s.%s.%s', major_version, minor_version, patch_version)
// Set version to be used in pom.properties
project.version = version
// Set version to be set as jar name
project.build.finalName = project.artifactId + "-" + version
</source>
</configuration>
</execution>
</executions>
</plugin>
來源
2014-11-15 19:24:36
fyr
我敢打賭,你將不得不爲這個編寫一個特殊的maven插件。 –
@AndrewWhite投注丟失;-) –