如何在Master和Child POM

时间:2016-12-26 11:29:32

标签: maven maven-profiles

我有一个主POM文件,它定义了两个配置文件:QA和Production。它使用properties-maven-plugin来设置一些变量,这些变量稍后由wildfly-maven-plugin用于将包部署到Web服务器。

这样的事情: [MASTER POM]

    <profile>
        <id>qa</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>properties-maven-plugin</artifactId>
                    <version>1.0.0</version>
                    <executions>
                        <execution>
                            <phase>initialize</phase>
                            <goals>
                                <goal>read-project-properties</goal>
                            </goals>
                            <configuration>
                                <files>
                                    <file>../build-qa.properties</file>
                                </files>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>

关于儿童POM:

<parent>
    <groupId>fhng.apps</groupId>
    <artifactId>fhng-build-all</artifactId>
    <version>1.0</version>
</parent>
(...)
<plugin>
    <groupId>org.wildfly.plugins</groupId>
    <artifactId>wildfly-maven-plugin</artifactId>
    <version>1.1.0.Alpha11</version>
    <executions>
        <execution>
        <phase>install</phase>
        <goals>
            <goal>deploy</goal>
        </goals>
        </execution>
    </executions>
    <configuration>
        <hostname>${wildfly.server}</hostname>
        <port>${wildfly.port}</port>
        <username>${wildfly.username}</username>
        <password>${wildfly.password}</password>
        <filename>myapp.war</filename>
    </configuration>
</plugin>

主POM位于项目根目录上,每个特定的Web应用程序都位于子文件夹中。如果我从每个特定项目文件夹运行mvn install,这都有效。我非常希望运行&#34; mvn -Pqa clean install&#34;从主pom文件夹。但它失败了,因为主pom引用了.. \ build-qa.properties,它们适用于每个项目,但显然在父目录中无效。

是解决这个问题的方法吗?是否可以引用相对于Master POM文件夹的文件,而不管构建哪个特定的POM?我知道这种方法打破了maven的前提,即父包不一定必须存在于我们的工作目录中。

作为替代方法,有没有办法将属性文件作为父包的工件引用?那么maven能够从repo中获取所述父包并使用其中的文件吗?

我也会接受一种方式来跳过&#34;跳过&#34; ou&#34;禁用&#34;父pom上的初始化/编译/安装阶段,以便它不会尝试读取.properties文件。

谢谢!

1 个答案:

答案 0 :(得分:1)

如果在根文件夹中放入目录.mvn/,则可以通过${maven.multiModuleProjectDirectory}

引用根文件夹

我目前的情况:

<file>${maven.multiModuleProjectDirectory}/build-qa.properties</file>

参考:http://takari.io/2015/03/20/mmp.html

PS。请记住,空文件夹不适用于git