在我们的一个项目中,我们使用properties-maven-plugin的read-project-properties目标来读取文件中的属性值,然后将其用于过滤资源.有关此过程的一般用途的讨论,请参阅此文章.
我们希望使用开发人员特定settings.xml中定义的合适配置文件覆盖文件中找到的一些值(与我们覆盖POM中设置的属性的方式相同).
但是,这不适用于properties-maven-plugin设置的属性.
我们如何实现目标?
作为一种解决方法,我们目前正在使用properties-maven-plugin注册一个额外的开发人员特定文件来实现此效果,但使用常规方式(配置文件)会更方便.
更一般地说,问题是:properties-maven-plugin的read-project-properties目标设置的属性如何与maven的属性定义优先级层次结合,这在这篇非常有用的博客文章中有所描述.
我将POM的相关元素提取到一个演示我的问题的玩具项目中.这是玩具项目的POM:
<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>xxx</groupId>
<artifactId>MavenTest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Maven Test</name>
<description>A maven project to test filtering and the maven-properties-plugin</description>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<executions>
<!-- Read properties from a file -->
<execution>
<id>load-filter-properties</id>
<goals>
<goal>read-project-properties</goal>
</goals>
<phase>initialize</phase>
<configuration>
<files>
<file>filters/filterTest.properties</file>
</files>
<quiet>false</quiet>
</configuration>
</execution>
<!-- The following execution is for debug purposes only -->
<execution>
<id>write-project-properties</id>
<inherited>false</inherited>
<goals>
<goal>write-project-properties</goal>
</goals>
<phase>package</phase>
<configuration>
<outputFile>filters/project.properties</outputFile>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12-beta-1</version>
</dependency>
</dependencies>
</project>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2241 次 |
| 最近记录: |