我想将buildnumber-maven-plugin中的buildNumber
放在XML文件中。
我配置了内部版本号插件。我可以看到它的工作原理,因为finalName是用内部版本号设置的。然后,我配置了资源过滤。我可以看到资源deployment.xml
已被过滤,因为它替代了${project.version}
。但是,它不能代替${buildNumber}
。为了使其正常工作,我必须做些什么?我查看了Maven build number plugin, how to save the build number in a file?,但它不能像那里一样工作,尽管几乎完成了相同的工作。
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