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

2020-06-30 05:25发布

问题:

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?

回答1:

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



回答2:

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



标签: maven profile