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

此生再无相见时 提交于 2020-01-01 07:46:10

问题


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



来源:https://stackoverflow.com/questions/9972265/in-maven-how-to-run-a-plugin-based-on-a-specific-profile

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!