Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Maven, how to run a plugin based on a specific profile

Tags:

profile

maven

I have a Maven project that has 3 modules. These are built by the parent pom.xml

I now have a requirement that I need to run one plugin from inside one of the sub modules' pom.xml files based on the profile selected.

How can I specify that this plugin should only run when a certain profile is used in build?

like image 922
mandy Avatar asked Apr 02 '12 07:04

mandy


People also ask

How do I run a specific profile in Maven?

Open Maven settings. m2 directory where %USER_HOME% represents the user home directory. If settings. xml file is not there, then create a new one. Add test profile as an active profile using active Profiles node as shown below in example.

What is profiling in Maven?

A profile in Maven is an alternative set of configuration values which set or override default values. Using a profile, you can customize a build for different environments. Profiles are configured in the pom. xml and are given an identifier.

Which element activates a profile by default in Maven?

Profiles can be activated in the Maven settings, via the <activeProfiles> section. This section takes a list of <activeProfile> elements, each containing a profile-id inside. Profiles listed in the <activeProfiles> tag would be activated by default every time a project use it.


2 Answers

Please read the documentation on build profiles here: http://maven.apache.org/guides/introduction/introduction-to-profiles.html

You basically need to define a profile in your sub-module's POM and include that plugin in the profile's plugin section. Using the plugin's execution tag, you can define which build phase the plugin should run in.

See here for an example: Using maven profiles to control build execution

like image 183
nwinkler Avatar answered Oct 02 '22 00:10

nwinkler


What worked in this case for me was to use the same profile as in the main pom.xml inside the sub modules pom.xml.

basically what I wanted was to be able to run a plugin from inside the sub modules pom.xml, only when a certain profile 'say X' was run in the main pom.xml

What I did was create a profile 'X' inside the sub modules pom.xml and placed that plugin inside this profile.

Now when profile X is run from main pom.xml, this plugin from the sub module's pom file is also run.

was other profiles , this plugin is not triggered.

Hope it helps someone:)

like image 43
mandy Avatar answered Oct 02 '22 00:10

mandy