Maven alternate pom

Mavenpom.xml

Maven Problem Overview


Is there an argument when calling a maven build to specify an alternate file in place of the standard pom.xml file name?

Basically, I have a need to run the test goal of my maven build with a variety of configurations. Right now I am having to use an external script to update the standard pom with this configurations, then revert the file after. I would much rather just be able to maintain several seperate configuration files and call maven with the specific one I need.

What I am wondering is if there is some way to override the pom.xml such as

mvn clean test   (uses standard pom.xml)
mvn clean test -Dmaven.source=alternate.xml
mvn clean test -Dmaven.source=alternate2.xml

Is this possible?

Maven Solutions


Solution 1 - Maven

use the -f option:

mvn -f <other pom file>

Solution 2 - Maven

I will leave the accepted answer as just that, since it is the proper solution to running with an alternate pom file. However, for the use case I described above, I now feel the correct methodology would be to use maven profiles within the pom file.

Maven Profiles Introduction

With profiles, all versions of the test configurations can be contained within the master pom file and then executed as follows:

mvn clean test -PstandardConfig
mvn clean test -PalternateConfig
mvn clean test -PanotherConfig

Solution 3 - Maven

I found this very interesting solution when I got the final answer. I follow the following approach:-

> mvn -f yourPomfil.xml goal

where the goal can be clean, verify, package, install, deploy and other maven goals

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMike ClarkView Question on Stackoverflow
Solution 1 - MavendavekView Answer on Stackoverflow
Solution 2 - MavenMike ClarkView Answer on Stackoverflow
Solution 3 - MavenKidaneView Answer on Stackoverflow