【发布时间】:2013-09-05 14:38:55
【问题描述】:
我有一个多模块项目,对不同的模块版本有很多依赖。目前版本是硬编码的,需要手动更改它们。所以我决定将它们全部放到一个属性文件中,并在项目构建期间从中获取属性值。
这是我尝试的方法:
根 pom.xml
<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>./version.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
文件 version.properties
module1.version=1.1
module2.version=1.8
module3.version=5.4
模块 pom.xml 示例
<properties>
<module1.project.version>${module1.version}</module1.project.version>
</properties>
<parent>
<groupId>com.mymodule</groupId>
<artifactId>test</artifactId>
<version>${module1.version}</version>
<relativePath>../pom.xml</relativePath>
</parent>
构建失败:
未能执行目标 org.codehaus.mojo:build-helper-maven-plugin:1.7:parse-version 项目 ccm-agent 上的 (parse-versions):执行 parse-versions 目标 org.codehaus.mojo:build-helper-maven-plugin:1.7:parse-version 失败的。 NullPointerException -> [帮助 1] org.apache.maven.lifecycle.LifecycleExecutionException: 失败 执行目标 org.codehaus.mojo:build-helper-maven-plugin:1.7:parse-version 项目 ccm-agent 上的 (parse-versions):执行 parse-versions 目标 org.codehaus.mojo:build-helper-maven-plugin:1.7:parse-version 失败了。
如何从文件中读取一些属性并正确配置 pom.xml?
【问题讨论】:
标签: maven