您遇到了
properties-maven-plugin
的一个缺陷,这个问题已经在今年早些时候被
报告,但修复还未成为新版本的一部分:
无法解释的“循环属性定义”#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
类,目前最新的插件快照版本尚未修复。
您可以按照以下步骤再次测试:将以下内容添加到您的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过滤,就不存在同样的问题。以下是一个POM代码片段示例:
<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