您遇到了 properties-maven-plugin 的错误,今年早些时候已经是 reported,但修复尚未包含在新版本中:
无根据的“循环属性定义”#27
确实,有一个简单的pom.xml,内容如下:
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<id>read-install-properties</id>
<phase>validate</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>src/main/resources/build.properties</file>
</files>
</configuration>
</execution>
<execution>
<id>write-install-properties</id>
<phase>validate</phase>
<goals>
<goal>write-project-properties</goal>
</goals>
<configuration>
<outputFile>target/build.properties</outputFile>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
src/main/resources/build.properties 内容简单:
C = ${A} + ${B} + ${B}
并调用 Maven:
mvn clean validate -DA=1 -DB=2
会导致
[ERROR] Failed to execute goal org.codehaus.mojo:properties-maven-plugin:1.0.0:read-project-properties (read-install-properties) on pr
oject sample: Circular property definition: C=${A} + ${B} + ${B} -> A=1 -> B=2 -> B=2 -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
相关组件是CircularDefinitionPreventer 类,尚未通过插件的最新SNAPSHOT 版本修复。
您可以按以下方式再次对其进行测试:将以下部分添加到您的 pom 文件中:
<pluginRepositories>
<pluginRepository>
<id>apache.snapshots</id>
<name>Maven Plugin Snapshots</name>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
并将插件版本更改为1.0.1-SNAPSHOT。这将允许您使用插件的最新 SNAPSHOT 版本,但尚未提供修复程序(在撰写本文时)。
Maven filtering 不存在相同的问题。具有以下示例 POM sn-p:
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
使用与上面相同的文件并执行
mvn clean package -DA=1 -DB2
我们将在生成的.jar 文件中包含build.properties 文件的内容:
C = 1 + 2 + 2