【发布时间】:2020-06-17 19:28:56
【问题描述】:
我想将 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>
目标/类/deployment.xml
<root>
<build>
<buildNumber>${buildNumber}</buildNumber>
<buildNumber>1.0.0-BUILD-SNAPSHOT</buildNumber>
<buildNumber>${project.finalName}</buildNumber>
</build>
</root>
我现在注意到一些奇怪的事情:在 maven 安装期间,内部版本号首先被替换为 XML 文件,然后 XML 文件再次被替换为上面的 XML 文件,其中 ${buildNumber} 未被替换。
我尝试关闭额外的复制步骤,但它似乎没有达到我期望的效果(我仍然有同样的问题):
[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 文件中。我想我可以忍受这一点,虽然我仍然不明白为什么文件target/classes/deployment.xml 在替换 buildNumber 后会重新创建。
更奇怪的是:当我编辑 src/main/resources/deployment.xml 时,文件 target/classes/deployment.xml 也会更新。一定是eclipse IDE做的吧?
我将 deployment.xml 移至 resources-filtered/deployment.xml,但覆盖行为仍然存在。
【问题讨论】:
标签: eclipse maven pom.xml versioning