How to reference a properties file on Master and Child POM's

1k views Asked by At

I have a master POM file that defines two profiles: QA and Production. It uses the properties-maven-plugin to set some vars that are later used by the wildfly-maven-plugin to deploy the packages to the web server.

Something like this: [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>

And on the Child POMs:

<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>

the Master POM is located on the project root and each particular web application is located on a sub-folder. This works if I run mvn install from each particular project folder. I would very much like to run "mvn -Pqa clean install" from the master pom folder. However it fails because the master pom references ..\build-qa.properties which works from each project but obviously is invalid from the parent directory.

Is where a way to solve this? Is it possible to reference a file relative to the Master POM folder, irrespective of which particular POM is built? I understand that this approach breaks the maven premise that the parent package must not necessarily be present on our working dir.

As an alternative, is there a way to reference the properties files as an artifact of the parent package? So that maven is able to get said parent package from the repo and use a file inside it?

I would also accept a way to "skip" ou "disable" the initialize/compile/install phase on the parent pom so that it won't try to read the .properties files.

Thank you!

1

There are 1 answers

0
michaldo On BEST ANSWER

If in root folder you put directory .mvn/, you can refer to root folder by ${maven.multiModuleProjectDirectory}

I current case:

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

Ref: http://takari.io/2015/03/20/mmp.html

PS. Remember that empty folder is not comitted to git