Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In a Maven multi-module project, how can I disable a plugin in one child?

I have a maven multi-module project (boy, I've written that opening way too many times on this site). Almost all the modules (that is, the ones that have code in them) should run the maven-site-plugin to generate reports about code coverage, etc. These have a detailed shared configuration -- which reports to run, which files to cover/exclude for certain plugins, etc.

However, there are a few modules that deal with packaging -- running the assembly plugin to generate a tarball, etc. These gain nothing from running a site report -- there's no code to analyze, no tests to report on.

So I have a lot of modules that need to share plugin configuration, and a few modules that need to not run the plugin, preferably at all. I can do the former (share configuration) if I put the plugin in the <build> section of the parent POM, but I can't seem to turn off the plugin when I need to in this case. I can do the latter (avoid running the plugin) if I push configuration down to each module's own POM, but I can't figure out a good way to share the configuration information in this case.

Is what I want -- shared configuration, for a plugin that's sometimes disabled by a child module -- even possible? If so, how?

like image 786
Coderer Avatar asked Oct 17 '11 23:10

Coderer


People also ask

What is Maven clean plugin?

The Maven Clean Plugin, as the name implies, attempts to clean the files and directories generated by Maven during its build. While there are plugins that generate additional files, the Clean Plugin assumes that these files are generated inside the target directory.

What is the use of multi-module project in Maven?

A multi-module project is built from an aggregator POM that manages a group of submodules. In most cases, the aggregator is located in the project's root directory and must have packaging of type pom. The submodules are regular Maven projects, and they can be built separately or through the aggregator POM.

How do I skip a Maven build module?

Maven version 3.2. 1 added this feature, you can use the -pl switch (shortcut for --projects list) with ! or - (source) to exclude certain submodules. Be careful in bash the character ! is a special character, so you either have to single quote it (like I did) or escape it with the backslash character.


1 Answers

By "run the plugin", I'm assuming you mean that the plugin is bound to a lifecycle phase, and you'd like to unbind it in some modules. First, you could consider changing your POM inheritance so that the modules that don't need the plugins have one parent and the ones that do have a different parent. If you don't want to do that, then you can explicitly set the execution phase to "nothing" in a child module. E.g. if you had a parent pom configuration like this:

<plugin>     <groupId>org.codehaus.mojo</groupId>     <artifactId>exec-maven-plugin</artifactId>     <version>1.2.1</version>     <executions>         <execution>             <id>i-do-something</id>             <phase>initialize</phase>             <goals>                 <goal>exec</goal>             </goals>             <configuration>                 ... lots of configuration             </configuration>         </execution>     </executions> </plugin> 

Then in a child module, you could do this:

<plugin>     <groupId>org.codehaus.mojo</groupId>     <artifactId>exec-maven-plugin</artifactId>     <version>1.2.1</version>     <executions>         <execution>             <id>i-do-something</id>             <phase/>         </execution>     </executions> </plugin> 

Because it's the same plugin and the same execution id, it overrides the configuration specified in the parent, and now the plugin isn't bound to a phase in the child project.

like image 87
Ryan Stewart Avatar answered Sep 18 '22 18:09

Ryan Stewart