Enterprise Java

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.
 
 
 
 
 

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <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.

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <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:

[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.

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <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).

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <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.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments
Back to top button