您的configuration 元素在execution 中定义,因此仅适用于execution。
因此,要么调用mvn initialize(或initialize 之后的阶段)来使用当前execution 绑定的configuration。
或者使用全局configuration:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<configuration>
<files>
<file>etc/config/dev.properties</file>
</files>
</configuration>
...
</plugin>
然后调用
mvn properties:read-project-properties
但这在此插件的特定情况下没有多大意义(您希望属性在构建期间可用),所以这为您提供了第一个解决方案。
更新:我自己做了一个测试,并且确实使用了以下 POM:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.stackoverflow</groupId>
<artifactId>Q2664362</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>etc/config/dev.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
运行mvn test 将不起作用:maven 将尝试下载junit:jar:${junit.version}(即它不使用属性的值),这显然会失败。
$ mvn 测试
[INFO] 正在扫描项目...
[信息] --------------------------------------------- -------------------------
[信息] 构建 SO - Q2664362 - maven-properties-plugin 演示
[INFO] 任务段:[测试]
[信息] --------------------------------------------- -------------------------
[信息] [属性:读取项目属性 {执行:默认}]
[信息] [资源:资源{执行:默认资源}]
[INFO] 使用 'UTF-8' 编码复制过滤的资源。
[INFO] 跳过不存在的资源目录 /home/pascal/Projects/stackoverflow/Q2664362/src/main/resources
下载:http://repo1.maven.org/maven2/junit/junit/${junit.version}/junit-${junit.version}.pom
[信息] 在存储库中心 (http://repo1.maven.org/maven2) 中找不到资源“junit:junit:pom:${junit.version}”
[信息] [编译器:编译{执行:默认编译}]
[INFO] 无需编译 - 所有类都是最新的
[信息] [资源:testResources {执行:默认-testResources}]
[INFO] 使用 'UTF-8' 编码复制过滤的资源。
[INFO] 跳过不存在的资源目录 /home/pascal/Projects/stackoverflow/Q2664362/src/test/resources
下载:http://repo1.maven.org/maven2/junit/junit/${junit.version}/junit-${junit.version}.jar
[信息] 在存储库中心 (http://repo1.maven.org/maven2) 中找不到资源“junit:junit:jar:${junit.version}”
[信息] --------------------------------------------- -------------------------
[错误] 构建错误
[信息] --------------------------------------------- -------------------------
[INFO] 无法解析工件。
...
奇怪的是依赖的下载发生在properties:read-project-properties之后。我不确定,但这听起来像是一个错误,你应该打开an issue。