Maven plugin config inheritance

553 views Asked by At

Given: parent pom with a certain config for a plugin in the build/plugins section. child having as parent the above pom.

Question: is the child going to inherit the parent config for the plugin in discussion?

Thanks

1

There are 1 answers

1
OldCurmudgeon On

To an extent - yes - but I expect there are limits.

Here's a cut-down example of some uses of inheritance. This shows re-use of project properties and dependency details. I am sure there are other examples.

Parent 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>
  <groupId>com.xxx</groupId>
  <artifactId>ArtefactID</artifactId>
  <version>1.2.3.4</version>
  <packaging>pom</packaging>

  <name>${project.artifactId} - ${project.version}</name>
  <modules>
    <module>AModule</module>
    <module>AnotherModule</module>
  </modules>
  <dependencyManagement>
    <dependencies>
      <dependency>
        <!-- Re-use project details. -->
        <groupId>${project.groupId}</groupId>
        <artifactId>AModule</artifactId>
        <version>${project.version}</version>
        <scope>provided</scope>
      </dependency>
      <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>AnotherModule</artifactId>
        <version>${project.version}</version>
        <scope>provided</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>
</project>

Child 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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>com.xxx</groupId>
    <artifactId>ArtefactID</artifactId>
    <version>1.2.3.4</version>
  </parent>

  <!-- Inherits project version from parent POM -->
  <name>AModule - ${project.version}</name>
  <artifactId>AModule</artifactId>
  <packaging>jar</packaging>

  <dependencies>
   <dependency>
      <!-- Inherits version and scope from parent POM -->
      <groupId>${project.groupId}</groupId>
      <artifactId>ANotherModule</artifactId>
    </dependency>
  </dependencies>
</project>