Search code examples
javamavenmaven-3maven-plugin

Extra plugins in child pom which are not inherited


I know the concept of super pom and inheritance. But still I see extra plugins magically coming up in my child module effective pom.

The project is very simple :

enter image description here

We have 2 POM -one for parent module and one for child module.

Parent module :

<?xml version="1.0" encoding="UTF-8"?>

<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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.practice</groupId>
  <artifactId>learning-maven</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>pom</packaging>

  <modules>
    <module>child-module1</module>
  </modules>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <configuration>
            <source>1.8</source>
            <target>1.8</target>
          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>


    <plugins>
      <plugin>
        <groupId>fr.jcgay.maven.plugins</groupId>
        <artifactId>buildplan-maven-plugin</artifactId>
        <version>1.3</version>
      </plugin>
    </plugins>


  </build>
</project>

Child module POM :

<?xml version="1.0" encoding="UTF-8"?>

<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>com.practice</groupId>
        <artifactId>learning-maven</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <artifactId>child-module1</artifactId>
    <version>1.0-SNAPSHOT</version>

</project>

If I generate effective POM of child and parent module I get this : (I am showing the effective POM data of plugins and goals through buildplan-maven-plugin for ease of reading. I have checked these plugin data with respect to effective POM too.)

[INFO] ------------------------------------------------------------------------
[INFO] Building learning-maven 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- buildplan-maven-plugin:1.3:list (default-cli) @ learning-maven ---
[INFO] Build Plan for learning-maven: 
----------------------------------------------------------
PLUGIN               | PHASE   | ID              | GOAL   
----------------------------------------------------------
maven-install-plugin | install | default-install | install
maven-deploy-plugin  | deploy  | default-deploy  | deploy 
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] Building child-module1 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- buildplan-maven-plugin:1.3:list (default-cli) @ child-module1 ---
[INFO] Build Plan for child-module1: 
---------------------------------------------------------------------------------------
PLUGIN                 | PHASE                  | ID                    | GOAL         
---------------------------------------------------------------------------------------
maven-resources-plugin | process-resources      | default-resources     | resources    
maven-compiler-plugin  | compile                | default-compile       | compile      
maven-resources-plugin | process-test-resources | default-testResources | testResources
maven-compiler-plugin  | test-compile           | default-testCompile   | testCompile  
maven-surefire-plugin  | test                   | default-test          | test         
maven-jar-plugin       | package                | default-jar           | jar          
maven-install-plugin   | install                | default-install       | install      
maven-deploy-plugin    | deploy                 | default-deploy        | deploy       
[INFO] ------------------------------------------------------------------------

If you see in child module , you are getting more plugins than the parent. If you want to see the super POM , it is here. So where does this extra plugins coming from in child module ?


Solution

  • I do not see it in your child pom, but you probably set the packaging to jar somewhere. The standard lifecycle of Maven defines several goals to be called depending on the packaging, and the Maven plugins you list would fit well to those goals.