gpt4 book ai didi

java - 子pom中不继承的额外插件

转载 作者:行者123 更新时间:2023-12-02 09:54:55 26 4
gpt4 key购买 nike

我知道 super 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] ------------------------------------------------------------------------

如果您在子模块中看到,则您获得的插件比父模块多。如果你想看 super POM,那就是here 。那么子模块中的这些额外插件来自哪里?

最佳答案

我在您的子 pom 中没有看到它,但您可能将打包设置为 jar 某处。 Maven 的标准生命周期定义了根据打包调用的多个目标,并且您列出的 Maven 插件非常适合这些目标。

关于java - 子pom中不继承的额外插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56065083/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com