我有以下Maven项目结构:
xyz
|
-props
| |
| - root.properties
|
-module_a
| |
| -pom.xml
|
-pom.xml
我的根工件定义了一个子模块(module_a),这是引用父工件。 在根pom.xml中,我正在使用常见的props文件夹中读取属性文件 org.codehaus.mojo:properties-maven-plugin:1.0-alpha-2 插件。
当我发行时 mvn clean package 命令我得到以下putput:
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] my_artifact
[INFO] module_a
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building my_artifact 1.0.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ my_artifact ---
[INFO]
[INFO] --- properties-maven-plugin:1.0-alpha-2:read-project-properties (default) @ my_artifact ---
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building module_a 1.0.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ module_a ---
[INFO]
[INFO] --- properties-maven-plugin:1.0-alpha-2:read-project-properties (default) @ module_a ---
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] my_artifact ....................................... SUCCESS [0.234s]
[INFO] module_a .......................................... FAILURE [0.000s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.344s
[INFO] Finished at: Thu Aug 09 15:37:46 CEST 2012
[INFO] Final Memory: 2M/5M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:properties-maven-plugin:1.0-alpha-2:read-project-properties (default) on project module_a: Properties file not found: G:\java\xyz\module_a\props\root.properties -> [Help 1]
[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/MojoExecutionException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn <goals> -rf :module_a
在子模块中,Maven尝试从不常见的子文件夹中读取属性文件。任何人都可以帮我解决这个问题吗? 谢谢
答案 0 :(得分:2)
当maven评估pom文件并创建有效的poms(与继承聚合)时,某些属性将被排除在继承之外。这些是从project。*开始的,因此也是project.basedir。这就是为什么你不能在父项中加载属性文件的地方定义属性。
此行为的原因是隔离。每个模块都应该与maven存储库之外的所有模块隔离。即使使用settings.xml配置文件也会违反此不变量,并且您将失去构建的可移植性。
在许多情况下,这种不变量是不必要的,所以如果你有许多模块并且想要使用一个属性文件,你可以做的是:
另一种方法是通过扩展AbstractMavenLifecycleParticipant来编写maven扩展,并使用maven api在那里加载属性文件,以确定项目的根目录。
答案 1 :(得分:0)
我遇到了类似的问题。
build.properties
文件 [ERROR] Failed to execute goal org.codehaus.mojo:properties-maven-plugin:1.0-alpha-2:read-project-properties (default) on project attachment-services: Properties file not found: /home/raz/git/parent/attachment-services/build.properties -> [Help 1]
要解决此问题,我在新模块的pom.xml
中添加了以下内容
<properties>
<build.properties.location>..</build.properties.location>
</properties>
当然,build.properties.location
已在父pom中定义,例如:
<properties>
<build.properties.location>${project.basedir</build.properties.location
</properties>