我试图强制使用maven enforcer插件设置属性。该属性应指向一个目录,并用作某些系统范围依赖项的基本目录。我有以下pom.xml
:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>maven-enforcer-systempath</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.example</groupId>
<artifactId>bar</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${non.existent.property}/bar.jar</systemPath>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.4.1</version>
<executions>
<execution>
<id>enforce-property</id>
<goals>
<goal>enforce</goal>
</goals>
<phase>validate</phase>
<configuration>
<rules>
<requireProperty>
<property>non.existent.property</property>
<message>"non.existent.property" must point to a directory</message>
</requireProperty>
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
现在当我运行未设置属性non.existent.property
的项目时,我得到以下输出:
[INFO] Scanning for projects...
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[ERROR] 'dependencies.dependency.systemPath' for org.example:bar:jar must specify an absolute path but is ${non.existent.property}/bar.jar @ line 14, column 16
@
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR] The project org.example:maven-enforcer-systempath:0.0.1-SNAPSHOT (C:\Users\workingcopy\maven-enforcer-systempath\pom.xml) has 1 error
[ERROR] 'dependencies.dependency.systemPath' for org.example:bar:jar must specify an absolute path but is ${non.existent.property}/bar.jar @ line 14, column 16
[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/ProjectBuildingException
在调用enforcer插件之前出现报告的错误。我相信这是因为documentation of the enforce goal州:
需要在范围内对工件进行依赖项收集:test。
如何在收集依赖项之前强制设置属性?