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.
 
 
 
 
 

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  <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
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  <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
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  <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
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  <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.
Do you want to know how to develop your skillset to become a Java Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
I agree to the Terms and Privacy Policy
Subscribe
Notify of
guest


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

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Back to top button