2015-02-09 24 views
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 

有什么我错过了?

+0

因为它们是由[buildnumber-maven-plugin]提供的(http://mojo.codehaus.org/buildnumber-maven-plugin/create-mojo.html)。 – khmarbaise 2015-02-09 11:41:20

+0

顺便说一句:为什么你改变了buildnumber-maven-plugin的阶段,并没有保留默认值?删除buildnumber-maven-plugin的' ...'标签。 – khmarbaise 2015-02-09 11:42:28

+0

@khmarbaise buildnumber-maven-plugin正是我使用的插件(请参阅问题中的pom小程序)。 sniplet是从这里复制的:http://mojo.codehaus.org/buildnumber-maven-plugin/usage.html,包括阶段标签。但是你是对的,它并不是必需的,但它不应该破坏功能,因为在过程资源阶段之前,资源被过滤。 – 2015-02-09 12:16:16

回答

0

这是一个更多的工作,比答案,但我想 a validate其次install为我工作。但是,这当然没有实际的方式来使用它...

你在此期间找到任何解决方案吗?