2
我想篩選我的buildNumber(git修訂號),由buildnumber-maven-plugin提供在一個屬性文件中,所以我可以從我的軟件訪問它。Maven Build Number插件版本沒有被過濾
我得到了以下POM:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>xxxx</groupId>
<artifactId>xxxx</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>xxxx</artifactId>
<build>
<resources>
<resource>
<directory>src/main/resources/</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
<configuration>
<shortRevisionLength>5</shortRevisionLength>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
和folloling文件的src /主/資源/ revision.properties:
branch = ${scmBranch}
revision = ${buildNumber}
version = ${project.version}
後,我跑了MVN乾淨安裝,這會產生以下輸出:
...
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ xxx ---
[INFO] Deleting D:\parsp\git\acm-utils\target
[INFO]
[INFO] --- buildnumber-maven-plugin:1.3:create (default) @ xxx ---
[INFO] ShortRevision tag detected. The value is '5'.
[INFO] Executing: cmd.exe /X /C "git rev-parse --verify --short=5 HEAD"
[INFO] Working directory: D:\parsp\git\acm-utils
[INFO] Storing buildNumber: 70cd7 at timestamp: 1423479895763
[INFO] Storing buildScmBranch: master
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ xxx ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO]
...
我在target/classes中得到了下面的resultinf文件,其中只有maven ve rsion被過濾到該文件中:
branch = ${scmBranch}
revision = ${buildNumber}
version = 1.0.0-SNAPSHOT
有什麼我錯過了?
因爲它們是由[buildnumber-maven-plugin]提供的(http://mojo.codehaus.org/buildnumber-maven-plugin/create-mojo.html)。 – khmarbaise 2015-02-09 11:41:20
順便說一句:爲什麼你改變了buildnumber-maven-plugin的階段,並沒有保留默認值?刪除buildnumber-maven-plugin的' ... '標籤。 –
khmarbaise
2015-02-09 11:42:28
@khmarbaise buildnumber-maven-plugin正是我使用的插件(請參閱問題中的pom小程序)。 sniplet是從這裏複製的:http://mojo.codehaus.org/buildnumber-maven-plugin/usage.html,包括階段標籤。但是你是對的,它並不是必需的,但它不應該破壞功能,因爲在過程資源階段之前,資源被過濾。 – 2015-02-09 12:16:16