Java Maven在POM中增加项目版本,但过滤后的资源得到旧版本

Java Maven在POM中增加项目版本,但过滤后的资源得到旧版本,java,maven,build,pom.xml,Java,Maven,Build,Pom.xml,我希望在maven构建中包含一个版本文件,以便每个构建自动增加构建编号,并在我的程序集中包含一个版本文件: <major>.<minor>.<buildNo> 1.0.2 --> 1.0.3 //include this in version.txt version.txt assembly.xml 棒极了 带有groovy的完整pom.xml 4.0.0 测试 版本 聚甲醛 ${versionNumber} UTF-8 UTF-8 ${ve

我希望在maven构建中包含一个版本文件,以便每个构建自动增加构建编号,并在我的程序集中包含一个版本文件:

<major>.<minor>.<buildNo>   1.0.2 --> 1.0.3   //include this in version.txt
version.txt assembly.xml 棒极了 带有groovy的完整pom.xml

4.0.0
测试
版本
聚甲醛
${versionNumber}
UTF-8
UTF-8
${versionNumber}
${buildNumber}
总工程师/总工程师
真的
org.codehaus.mojo
属性maven插件
1.0.0
初始化
读取项目属性
/建筑/物业
org.apache.maven.plugins
maven资源插件
2.7
过滤资源
资源
产生资源
org.codehaus.gmaven
groovy maven插件
org.codehaus.groovy
groovy all
2.4.3
准备包装
执行
导入java.nio.file*
def version=project.properties['proj.version']
def build=project.properties['proj.build']
if(build?.isNumber()){
build=构建为整数
建造++
Properties buildProps=新属性()
buildProps.setProperty('buildNumber',build.toString())
buildProps.setProperty('fullVersionNumber',version+'.+build)
buildProps.setProperty('versionNumber',version.toString())
Path buildFile=Path.get('./build.properties')
Path assemblyBuildFile=Path.get('./target/classes/build.properties')
File propsFile=新文件(buildFile.toUri())
Writer=null
试一试{
//更新build.properties
writer=propsFile.newWriter()
buildProps.store(writer,null)
//复制以供组装
复制(buildFile,assemblyBuildFile)
}捕获(例外e){
抛出新的运行时异常(e)
}最后{
if(writer)writer.close()
}
}否则{
抛出RuntimeException('无效的内部版本号:'+内部版本)
}
org.apache.maven.plugins
maven汇编插件
2.4
包自定义程序集
单一的
包裹
src/main/assembly.xml
最终文件
假的
拉链
目标/类别
/

更改阶段插件自动增量版本maven插件包:

   <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>autoincrement-versions-maven-plugin</artifactId>
            <version>2.0-SNAPSHOT</version>
            <executions>
               <execution>
                  <id>update-pom-versions</id>
                  <goals>
                     <goal>increment</goal>
                  </goals>
                  <phase>package</phase>
                  <configuration>
                     <autoIncrementVersion>true</autoIncrementVersion>
                  </configuration>
               </execution>
            </executions>
         </plugin>

org.codehaus.mojo
自动增量版本maven插件
2.0-快照
更新pom版本
增量
包裹
真的

不确定如何使用autoincrement插件执行此操作,但是我只是调用
versions:set
在我的CI脚本中的主构建目标之前。仍然在
target/classes
和汇编文件中获取旧版本orry autoincrement versions maven plugin=>package phase et not maven resources plugina你能用发布的pom验证这一点吗?我在
authoincrement
中设置了
package
,但仍然得到了以前的版本。
${proj.version}
<assembly>
    <id>asm</id>
    <formats>
        <format>zip</format>
    </formats>
    <fileSets>
        <fileSet>
            <directory>target/classes</directory>
            <outputDirectory>/</outputDirectory>
        </fileSet>
    </fileSets>
</assembly>
<?xml version="1.0" encoding="UTF-8"?>
<project>
   <modelVersion>4.0.0</modelVersion>
   <groupId>test</groupId>
   <artifactId>version</artifactId>
   <packaging>pom</packaging>
   <version>1.0.32</version>
   <properties>
      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
      <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
      <maven.build.timestamp.format>MMM-dd-YYYY HH:mm:ss</maven.build.timestamp.format>
      <build.timestamp>${maven.build.timestamp}</build.timestamp>
      <proj.version>${version}</proj.version}
   </properties>
   <pluginRepositories>
      <pluginRepository>
         <id>autoincrement-versions-maven-plugin</id>
         <name>autoincrement-versions-maven-plugin</name>
         <url>http://autoincrement-versions-maven-plugin.googlecode.com/svn/repo</url>
         <snapshots>
            <enabled>true</enabled>
         </snapshots>
      </pluginRepository>
   </pluginRepositories>
   <build>
      <resources>
         <resource>
            <directory>src/main</directory>
            <filtering>true</filtering>
         </resource>
      </resources>
      <plugins>
         <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>autoincrement-versions-maven-plugin</artifactId>
            <version>2.0-SNAPSHOT</version>
            <executions>
               <execution>
                  <id>update-pom-versions</id>
                  <goals>
                     <goal>increment</goal>
                  </goals>
                  <phase>generate-resources</phase>
                  <configuration>
                     <autoIncrementVersion>true</autoIncrementVersion>
                  </configuration>
               </execution>
            </executions>
         </plugin>
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.7</version>
            <executions>
               <execution>
                  <id>filter-resources</id>
                  <goals>
                     <goal>resources</goal>
                  </goals>
                  <phase>generate-resources</phase>
               </execution>
            </executions>
         </plugin>
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.4</version>
            <executions>
               <execution>
                  <id>package-custom-assembly</id>
                  <goals>
                     <goal>single</goal>
                  </goals>
                  <phase>package</phase>
                  <configuration>
                     <descriptor>src/main/assembly.xml</descriptor>
                     <finalName>finalfile</finalName>
                     <appendAssemblyId>false</appendAssemblyId>
                     <formats>
                        <format>zip</format>
                     </formats>
                     <fileSets>
                        <fileSet>
                           <directory>target/classes</directory>
                           <outputDirectory>/</outputDirectory>
                        </fileSet>
                     </fileSets>
                  </configuration>
               </execution>
            </executions>
         </plugin>
      </plugins>
   </build>
</project>
fullVersionNumber=1.0.6
versionNumber=1.0
buildNumber=6
 import java.nio.file.*
 def version = project.properties['proj.version']
 def build = project.properties['proj.build']
 if(build?.isNumber()){
    build = build as Integer
    build++
    Properties buildProps = new Properties()  
    buildProps.setProperty('buildNumber', build.toString())
    buildProps.setProperty('fullVersionNumber', version + '.' + build)
    buildProps.setProperty('versionNumber', version.toString())
    Path buildFile = Paths.get('./build.properties')
    Path assemblyBuildFile = Paths.get('./target/classes/build.properties')
    File propsFile = new File(buildFile.toUri())
    Writer writer = null
    try{
       //update build.properties
       writer = propsFile.newWriter()
       buildProps.store(writer, null)
       //copy for assembly
       Files.copy(buildFile, assemblyBuildFile)
    }catch(Exception e){
       throw new RuntimeException(e)
    }finally{
       if(writer) writer.close()
    }
 }else{
    throw RuntimeException('Invalid build number: ' + build)
 }
<?xml version="1.0" encoding="UTF-8"?>
<project>
   <modelVersion>4.0.0</modelVersion>
   <groupId>test</groupId>
   <artifactId>version</artifactId>
   <packaging>pom</packaging>
   <version>${versionNumber}</version>
   <properties>
      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
      <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
      <proj.version>${versionNumber}</proj.version>
      <proj.build>${buildNumber}</proj.build>
   </properties>
   <pluginRepositories>

   </pluginRepositories>
   <build>
      <resources>
         <resource>
            <directory>src/main</directory>
            <filtering>true</filtering>
         </resource>
      </resources>
      <plugins>
         <plugin>
           <groupId>org.codehaus.mojo</groupId>
           <artifactId>properties-maven-plugin</artifactId>
           <version>1.0.0</version>
           <executions>
             <execution>
               <phase>initialize</phase>
               <goals>
                 <goal>read-project-properties</goal>
               </goals>
               <configuration>
                 <files>
                   <file>./build.properties</file>
                 </files>
               </configuration>
             </execution>
           </executions>
         </plugin>
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.7</version>
            <executions>
               <execution>
                  <id>filter-resources</id>
                  <goals>
                     <goal>resources</goal>
                  </goals>
                  <phase>generate-resources</phase>
               </execution>
            </executions>
         </plugin>
         <plugin>
           <groupId>org.codehaus.gmaven</groupId>
           <artifactId>groovy-maven-plugin</artifactId>
           <dependencies>
             <dependency>
               <groupId>org.codehaus.groovy</groupId>
               <artifactId>groovy-all</artifactId>
               <version>2.4.3</version>
             </dependency>
           </dependencies>
          <executions>
          <execution>
            <phase>prepare-package</phase>
            <goals>
              <goal>execute</goal>
            </goals>
            <configuration>
              <source>
                import java.nio.file.*
                def version = project.properties['proj.version']
                def build = project.properties['proj.build']
                if(build?.isNumber()){
                   build = build as Integer
                   build++
                   Properties buildProps = new Properties()    
                   buildProps.setProperty('buildNumber', build.toString())
                   buildProps.setProperty('fullVersionNumber', version + '.' + build)
                   buildProps.setProperty('versionNumber', version.toString())
                   Path buildFile = Paths.get('./build.properties')
                   Path assemblyBuildFile = Paths.get('./target/classes/build.properties')  
                   File propsFile = new File(buildFile.toUri())
                   Writer writer = null
                   try{
                      //update build.properties
                      writer = propsFile.newWriter()
                      buildProps.store(writer, null)
                      //copy for assembly
                      Files.copy(buildFile, assemblyBuildFile)
                   }catch(Exception e){
                      throw new RuntimeException(e)
                   }finally{
                      if(writer) writer.close()
                   }
                }else{
                   throw RuntimeException('Invalid build number: ' + build)
                }

              </source>
            </configuration>
          </execution>
      </executions>
         </plugin>
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.4</version>
            <executions>
               <execution>
                  <id>package-custom-assembly</id>
                  <goals>
                     <goal>single</goal>
                  </goals>
                  <phase>package</phase>
                  <configuration>
                     <descriptor>src/main/assembly.xml</descriptor>
                     <finalName>finalfile</finalName>
                     <appendAssemblyId>false</appendAssemblyId>
                     <formats>
                        <format>zip</format>
                     </formats>
                     <fileSets>
                        <fileSet>
                           <directory>target/classes</directory>
                           <outputDirectory>/</outputDirectory>
                        </fileSet>
                     </fileSets>
                  </configuration>
               </execution>
            </executions>
         </plugin>
      </plugins>
   </build>
</project>
   <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>autoincrement-versions-maven-plugin</artifactId>
            <version>2.0-SNAPSHOT</version>
            <executions>
               <execution>
                  <id>update-pom-versions</id>
                  <goals>
                     <goal>increment</goal>
                  </goals>
                  <phase>package</phase>
                  <configuration>
                     <autoIncrementVersion>true</autoIncrementVersion>
                  </configuration>
               </execution>
            </executions>
         </plugin>