Maven and Profiles: Using the same plugin in two different profiles and have both active at the same time

白昼怎懂夜的黑 提交于 2019-12-04 07:35:34

You are in luck, the grunt goal of that plugin defines a skip property so you only need to set this property to true in your custom profile.

As such, you need to create a profile development that sets a custom property skipGrunt to true and a default profile that sets it to false.

Then, in the plugin configuration of the grunt goal, you can add

<configuration>
    <skip>${skipGrunt}</skip>
    <!-- rest of configuration -->
</configuration>

This remark can be made more general: when you need to skip a specific execution of a plugin, there's generally a custom skip property that you can set to true.

G.Broser says Reinstate Monica

Let me cite from the Maven forum:

My takeaway was that if one just jumps on profiles as the solution to every conditional situation, the build will grow a second head like a hydra in a bad horror flick and you'll really regret it.

The point is that profiles are often an expedient substitute for using Maven correctly. They should always be considered "last resort" unless you know what you are getting yourself into.

In my situation, [...]. Profiles work great for that, but I can see exactly where the hydra head fits on the beast now and don't intend on doing anything more with them unless absolutely necessary.

I have made my experiences with profiles. I second this view.

From a conceptual point of view you have two projects that have most of their things in common. This is where Maven's POM hierarchy with its inheritance comes into play:

product ... parent POM
  +- pom.xml ... contains build steps apart from Grunt and all other declarations 
  +- dev
  |    +- pom.xml ... almost empty since everything's inherited from parent
  |    +- ... sources, resources, etc. ...
  +- release
       +- pom.xml ... contains Grunt build step only, everything else's inherited from parent
                      redirecting <build>/<[[test]source|resource>/]|
                          [[test]output|testresource>/]directory> to ../dev/...

See The BaseBuild Element Set, Resources and The Build Element Set in the POM Reference for all the build directories to be redirected.

See Maven include another pom for plugin configuration:

The only correct answer is to use inheritance.

I second that, as well.

If you go for the profile nevertheless I recommend to call it dev rather than development. Your devs will be thankful forever. :)

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