指示父目录的 Maven2 属性 [英] Maven2 property that indicates the parent directory

查看:22
本文介绍了指示父目录的 Maven2 属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个多模块项目,就像这个:

I have a multi-modules project, like this one:

main-project/
    module1/
    module2/
        sub-module1/
        sub-module2/
        sub-module3/
        ...
    module3/
    module4/
    ...

我需要在 Maven2 中定义一组属性(取决于我要发布项目的环境).我不会使用 因为有很多属性......因此,我使用 Properties Maven2 插件.

I need to define a set of properties (that are dependent of the environment on which I want to release my project) in Maven2. I will not use <properties> as there is lots of properties... Thus, I use the Properties Maven2 plugin.

属性文件位于 main-project/ 目录中.如何在主 pom.xml 中设置正确的目录,以便为任何孩子指定在哪里可以找到属性文件?

The properties files are located in the main-project/ directory. How can I set the correct directory in the main pom.xml, in order to specify to any children where to find the properties file?

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>properties-maven-plugin</artifactId>
    <version>1.0-alpha-1</version>
    <executions>
        <execution>
            <phase>initialize</phase>
            <goals>
                <goal>read-project-properties</goal>
            </goals>
            <configuration>
                <files>
                    <file>???/env_${env}.properties</file>
                </files>
            </configuration>
        </execution>
    </executions>
</plugin>

如果我只设置<file>env_${env}.properties</file>,那么Maven2编译第一个模块时,就找不到main-project/env_dev.properties 文件.如果我设置 <file>../env_${env}.properties</file>,那么将在父级别或任何子模块级别引发错误...

If I set only <file>env_${env}.properties</file>, then when Maven2 compiles the first module, it will not find the main-project/env_dev.properties file. If I set <file>../env_${env}.properties</file>, then an error will be raised at the parent level, or at any sub-module level...

推荐答案

尝试在每个 pom 中设置一个属性以查找主项目目录.

Try setting a property in each pom to find the main project directory.

在父级中:

<properties>
    <main.basedir>${project.basedir}</main.basedir>
</properties>

在儿童中:

<properties>
    <main.basedir>${project.parent.basedir}</main.basedir>
</properties>

在孙辈中:

<properties>
    <main.basedir>${project.parent.parent.basedir}</main.basedir>
</properties>

这篇关于指示父目录的 Maven2 属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆