1

我正在尝试强制使用 maven 强制执行器插件设置属性。该属性应指向一个目录,并用作某些系统范围依赖项的基本目录。我有以下内容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

在调用执行器插件之前出现报告的错误。我相信这是因为强制目标的文档指出:

需要在范围内收集工件的依赖项:测试。

如何强制在收集依赖项之前设置属性?

4

0 回答 0