Igor Kromin |   Consultant. Coder. Blogger. Tinkerer. Gamer.

Many of the plugins that would be used in a typical Maven setup provide an option to skip execution of that plugin via the <skip> configuration parameter or in the case of the Surefire plugin, the -DskipTests system property. Unfortunately some plugins, like the WebLogic Maven Plugin do not offer this facility.

I had a situation where I wanted each of the developers to be able to locally do a build and automatically deploy to WebLogic, but I didn't want jobs executed by the CI pipeline to do any automatic deployments. Since the WebLogic plugin didn't offer a skip option, I had to find another way.

What I ended up doing was changing the <phase> for the plugin to a variable instead of it being static. Something like this...
 Maven
<plugin>
...
<execution>
...
<phase>${skipPluginPhase}</phase>
...
</execution>
...
</plugin>


Then I could define the value for the skipPluginPhase property like...
 Maven
<properties>
<skipPluginPhase>none</skipPluginPhase>
</properties>


Leaving it as 'none' would skip plugin execution, whereas putting in a valid phase like 'install' would execute the plugin as expected. The only change each developer would need to do locally was update their version of the pom.xml file to reflect this.

To avoid unnecessary editing of the pom.xml file it is also possible to set up a number of different profiles in your Maven build. The default profile could then set skipPluginPhase to a valid phase name and a profile set up just for the CI pipeline could set skipPluginPhase to none, whereby skipping plugin execution.



-i

A quick disclaimer...

Although I put in a great effort into researching all the topics I cover, mistakes can happen. Use of any information from my blog posts should be at own risk and I do not hold any liability towards any information misuse or damages caused by following any of my posts.

All content and opinions expressed on this Blog are my own and do not represent the opinions of my employer (Oracle). Use of any information contained in this blog post/article is subject to this disclaimer.
Hi! You can search my blog here ⤵
NOTE: (2022) This Blog is no longer maintained and I will not be answering any emails or comments.

I am now focusing on Atari Gamer.