简体   繁体   中英

Maven plugin config inheritance

Given: parent pom with a certain config for a plugin in the section. 部分中为插件添加了特定配置的父pom。 child having as parent the above pom.

Question: is the child going to inherit the parent config for the in discussion? 的父配置吗?

Thanks

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM