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?
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.
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.
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.
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
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:)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With