Prevent ‘No plugin found’ in multi-module maven
Defining a maven plugin on a submodule in a multi-module maven project can give us a ‘No plugin found’ error. Especially if we have a multi-module project and we want to apply a maven plugin in only one specific module this error occur pretty often.
Let’s say we have a multi-module root pom which looks like this.
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 | < modelVersion >4.0.0</ modelVersion > < groupId >com.jdriven.blog</ groupId > < artifactId >maven-plugin-multimodule</ artifactId > < version >0.1-SNAPSHOT</ version > < packaging >pom</ packaging > < modules > < module >module1</ module > <!-- Module1 is a regular jar --> < module >module2</ module > <!-- Module2 has tomcat7 plugin configured --> </ modules > </ project > |
Instinctively we add the plugin (tomcat7 for example) to this specific module module2
, like this.
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | < modelVersion >4.0.0</ modelVersion > < artifactId >maven-plugin-multimodule-module2</ artifactId > < packaging >war</ packaging > < parent > < groupId >com.jdriven.blog</ groupId > < artifactId >maven-plugin-multimodule</ artifactId > < version >0.1-SNAPSHOT</ version > < relativePath >../</ relativePath > </ parent > < build > < plugins > < plugin > < groupId >org.apache.tomcat.maven</ groupId > < artifactId >tomcat7-maven-plugin</ artifactId > < version >2.2</ version > < configuration > <!-- This is where our specific configuration goes --> </ configuration > </ plugin > </ plugins > </ build > </ project > |
When we run the command mvn tomcat7:help
on the multi-module root pom we get the following error:
1 2 3 | [ERROR] No plugin found for prefix 'tomcat7' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories |
The solution is very simple: We specify the plugin in the pluginManagement section of our multi-module root pom.
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | < modelVersion >4.0.0</ modelVersion > < groupId >com.jdriven.blog</ groupId > < artifactId >maven-plugin-multimodule</ artifactId > < version >0.1-SNAPSHOT</ version > < packaging >pom</ packaging > < modules > < module >module1</ module > <!-- Module1 is a regular jar --> < module >module2</ module > <!-- Module2 has tomcat7 plugin configured --> </ modules > < build > <!-- In the multi-module root pom, use the pluginManagement to define the version of the maven-plugin --> < pluginManagement > < plugins > < plugin > < groupId >org.apache.tomcat.maven</ groupId > < artifactId >tomcat7-maven-plugin</ artifactId > < version >2.2</ version > </ plugin > </ plugins > </ pluginManagement > </ build > </ project > |
And in our specific module module2
we clear the version of the plugin, since it is already defined in the multi-module root pom (the parent).
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | < modelVersion >4.0.0</ modelVersion > < artifactId >maven-plugin-multimodule-module2</ artifactId > < packaging >war</ packaging > < parent > < groupId >com.jdriven.blog</ groupId > < artifactId >maven-plugin-multimodule</ artifactId > < version >0.1-SNAPSHOT</ version > < relativePath >../</ relativePath > </ parent > < build > < plugins > < plugin > < groupId >org.apache.tomcat.maven</ groupId > < artifactId >tomcat7-maven-plugin</ artifactId > <!-- No version needed here, it is already defined in the multi-module root pom --> < configuration > <!-- This is where our specific configuration goes --> </ configuration > </ plugin > </ plugins > </ build > </ project > |
Now when can run the command mvn tomcat7:help
and get no error. We are ready to configure the plugin on our submodule.
Reference: | Prevent ‘No plugin found’ in multi-module maven from our JCG partner Willem Cheizoo at the JDriven blog. |