Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven alternate pom

Tags:

maven

pom.xml

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?

like image 930
Mike Clark Avatar asked Dec 23 '10 14:12

Mike Clark


People also ask

What is project Basedir in Maven?

project. basedir : The directory that the current project resides in. This means this points to where your Maven projects resides on your system. It corresponds to the location of the pom. xml file.

Can we have multiple POM files?

Yes you can use Maven Profiles to manage this. Obviously you can tweak this approach to suit your needs however works best.

What is Modelversion in POM xml?

model version is the version of project descriptor your POM conforms to. It needs to be included and is set. The value 4.0. 0 just indicated that it is compatible Maven 3.

What does POM stand for Maven?

A Project Object Model or POM is the fundamental unit of work in Maven. It is an XML file that contains information about the project and configuration details used by Maven to build the project. It contains default values for most projects.


2 Answers

use the -f option:

mvn -f <other pom file> 
like image 135
davek Avatar answered Oct 04 '22 04:10

davek


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 
like image 26
Mike Clark Avatar answered Oct 04 '22 04:10

Mike Clark