eclipse - Maven buildnumber,替换文件不起作用
问题描述
我想buildNumber
在 XML 文件中包含 from buildnumber-maven-plugin。
我配置了内部版本号插件。我可以看到它有效,因为 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>
目标/类/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
. 我想我可以忍受这一点,尽管我仍然不明白为什么target/classes/deployment.xml
在替换 buildNumber 后文件会重新创建。
更奇怪的是:当我编辑时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
推荐阅读
- laravel - 在 Laravel 6 上调用字符串上的成员函数 addDays()
- python - 将数据框行值设置为 numpy 数组值
- airflow - 如何将代理配置传递到 Airflow S3 连接
- couchdb - 无法理解 couchdb 中特定类型的视图
- azure - Azure Speech To Text cURL 调用失败
- java - 更改 Intellij IDEA 提示窗格的背景颜色
- .net - 卸载时使用 Installer 类实现的自定义操作不起作用
- mips32 - 读取十六进制并将其转换为十进制
- r - R - 理解 && 的行为
- listview - 如何使用按钮单击动态创建新列表?