Maven 内部版本号,替换文件不起作用



我想在一个XML文件中拥有来自buildnumber maven插件的buildNumber

我配置了内部版本号插件。我可以看出它是有效的,因为finalName是用内部版本号设置的。然后我配置了资源筛选。我可以看到资源deployment.xml被过滤了,因为它替换了${project.version}。但是,它并不能取代${buildNumber}。我必须做些什么才能让它发挥作用?我看了Maven版本号插件,如何将版本号保存在文件中?,但它并不像那里那样工作,尽管那里几乎都做了同样的事情。

pom.xml:

<!-- build number -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
<configuration>
<format>{0,number}</format>
<items>
<item>buildNumber</item>
</items>
<doCheck>false</doCheck>
<doUpdate>false</doUpdate>
</configuration>
</plugin>
</plugins>
<finalName>${project.artifactId}-${project.version}-r${buildNumber}</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/deployment.xml</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<excludes>
<exclude>**/deployment.xml</exclude>
</excludes>
</resource>
</resources>
</build>
<!-- dummy scm for build number plugin -->
<scm>
<connection>scm:git:http://127.0.0.1/dummy</connection>
<developerConnection>scm:git:https://127.0.0.1/dummy</developerConnection>
<tag>HEAD</tag>
<url>http://127.0.0.1/dummy</url>
</scm>

src/main/resources/deployment.xml

<root>
<build>
<buildNumber>${buildNumber}</buildNumber>
<buildNumber>${project.version}</buildNumber>
<buildNumber>${project.finalName}</buildNumber>
</build>
</root>

target/classes/deployment.xml

<root>
<build>
<buildNumber>${buildNumber}</buildNumber>
<buildNumber>1.0.0-BUILD-SNAPSHOT</buildNumber>
<buildNumber>${project.finalName}</buildNumber>
</build>
</root>

我现在注意到了一些奇怪的事情:在maven安装期间,内部版本号首先被替换到XML文件中,然后XML文件再次被上面没有替换${buildNumber}的XML文件替换。

我试着关闭额外的复制步骤,但似乎没有达到我预期的效果(我仍然有同样的问题(:

[INFO] --- maven-resources-plugin:3.1.0:copy-resources (copy-resources) @ rator ---
[INFO] Using 'Cp1252' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 83 resources
[INFO] 
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ rator ---
[INFO] Skipping the execution.
[INFO] 
.. compiling ..
[INFO] 
[INFO] --- maven-resources-plugin:3.1.0:testResources (default-testResources) @ rator ---
[INFO] Not copying test resources
[INFO] 

我在看目标/课程。当我查看target/xxx-1.0.0-BUILD-SNAPSHOT-r36/WEB-INF/classes/deployment.xml时,内部版本号似乎已正确打包到war文件中。我想我可以接受这一点,尽管我仍然不明白为什么在替换buildNumber之后会重新创建文件target/classes/deployment.xml

更奇怪的是:当我编辑src/main/resources/deployment.xml时,文件target/classes/deployment.xml也会更新。一定是eclipse IDE做了什么?

我将deployment.xml移到了resources-filtered/deployment.xml,但覆盖行为仍然存在。

在xml中有一个属性部分。通过这种方式,您可以告诉Maven您的自定义属性,这些属性将在构建时被替换。

<project>
<properties>
<buildNumber>YOUR_BUILD_NUMBER</buildNumber>
<anotherProperty>foo</anotherProperty>
</properties>
</project>

请参阅https://maven.apache.org/pom.html#Properties

这里是预定义Maven属性的非官方列表:https://github.com/cko/predefined_maven_properties/blob/master/README.md

最新更新