子pom中未继承的额外插件

时间:2019-05-09 17:57:24

标签: java maven maven-3 maven-plugin

我知道超级pom和继承的概念。但我仍然看到在子模块有效pom中神奇地出现了额外的插件。

该项目非常简单:

enter image description here

我们有2个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.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>

子模块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>

如果我生成子模块和父模块的有效POM,则会得到以下信息: (为了方便阅读,我正在通过buildplan-maven-plugin显示插件和目标的有效POM数据。我也已经检查了有关有效POM的这些插件数据。)

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

如果在子模块中看到,则您得到的插件比父模块更多。 如果要查看超级POM,则为here。 那么,这些额外的插件在子模块中来自哪里?

1 个答案:

答案 0 :(得分:1)

我在您的孩子pom中看不到它,但是您可能将包装设置为jar。 Maven的标准生命周期根据包装定义了几个要调用的目标,您列出的Maven插件很适合这些目标。

相关问题