【问题标题】:org.codehaus.mojo:properties-maven-plugin:1.0-alpha-2 errororg.codehaus.mojo:properties-maven-plugin:1.0-alpha-2 错误
【发布时间】:2012-08-06 19:08:26
【问题描述】:

我有以下 Maven 项目结构:

xyz
  |
  -props
  |  |
  |  - root.properties
  |
  -module_a
  |  |
  |  -pom.xml
  |
  -pom.xml

我的根工件定义了一个子模块 (module_a),它引用了父工件。 在根 pom.xml 中,我正在使用 common props 文件夹中读取一个属性文件 org.codehaus.mojo:properties-maven-plugin:1.0-alpha-2 插件。

当我发出 mvn 清洁包 命令我得到以下输入:

[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 尝试从不存在的子文件夹中读取属性文件。有人可以帮我解决这个问题吗? 谢谢

【问题讨论】:

    标签: maven properties


    【解决方案1】:

    我也遇到过类似的问题。

    • 我有一个父项目 pom.xml,它有一个 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>
    

    【讨论】:

      【解决方案2】:

      当 maven 评估 pom 文件并创建有效的 pom(与继承聚合)时,某些属性被排除在继承之外。这些是以 project.* 开头的,因此也是 project.basedir。这就是为什么你不能定义从哪里加载属性文件到父级的属性。

      这种行为的原因是孤立。每个模块都应该与除 Maven 存储库之外的所有内容隔离。即使使用 settings.xml 配置文件也会违反此不变量,并且您会失去构建的可移植性。

      这个不变量在很多情况下是不必要的,所以如果你有很多模块并且你想使用一个属性文件,你可以做的是:

      • 定义一个属性,例如根 pom 中的“filters.dir”到 ${project.basedir}/src/main/filters
      • 配置插件以从 ${filters.dir}/my.properties 加载属性文件
      • 现在您可以在任何子模块中将 filters.dir 覆盖为 ../src/main/filters
      • 如果您有许多子模块,您可以在根目录中为 filters.dir 定义错误的路径“../src/main/filters”,然后您不需要在任何子模块中定义该属性。为防止构建失败,您需要将插件设置为忽略失败。

      另一种方法是通过扩展 AbstractMavenLifecycleParticipant 编写 maven 扩展,并使用 maven api 加载属性文件以确定项目的根目录。

      【讨论】:

        猜你喜欢
        • 2019-04-30
        • 1970-01-01
        • 1970-01-01
        • 2011-11-12
        • 1970-01-01
        • 2012-07-12
        • 2013-05-01
        • 2018-12-25
        • 2016-09-27
        相关资源
        最近更新 更多