在 Parent Pom 中定义的 Maven Plugin 有时在没有声明的情况下不会在 Child 中触发

Maven Plugin defined in Parent Pom sometimes does not trigger in Child without declaration

在我的父 POM 中,我在 <pluginManagement><plugins>.

中定义了一个阶段 prepare-package 的依赖插件
<plugin>
    <artifactId>maven-resources-plugin</artifactId>
    <version>${version.plugin.resources}</version>
</plugin>
<plugin>
    <artifactId>maven-dependency-plugin</artifactId>
    <version>${version.plugin.dependency}</version>
    <executions>
        <execution>
            <id>copy-dependencies</id>
            <phase>prepare-package</phase>
            <goals>
                <goal>copy-dependencies</goal>
            </goals>
            <configuration>
            <outputDirectory>${classpathDir}</outputDirectory>
            <includeScope>runtime</includeScope>
            <excludeClassifiers>${dependencyClassifiers}</excludeClassifiers>
            </configuration>
        </execution>
    </executions>
</plugin>

在我的子 POM 中,我没有指定任何依赖插件。它没有被执行。我必须把它放在 <plugins> 中才能触发:

<plugin>
    <artifactId>maven-dependency-plugin</artifactId>
</plugin>

我使用的 Maven 目标是 clean install

我的问题是,为什么我必须在子 POM 中再次明确指定 maven-dependency-plugin

  1. 其他插件如 maven-jar-pluginmaven-resource-pluginmaven-compiler-plugin 是 运行,即使我没有在我的 POM 中重新声明它们。为什么不一致?
  2. 依赖项的阶段配置为 prepare-package,在 Maven lifecyclepackage 阶段之前,因此我认为它应该是 "executed in the order given up to the point of the one specified"。但事实并非如此,为什么?

提前感谢任何能够帮助我查询的人! :)

<pluginManagement> 部分用于在本项目和子项目之间共享插件配置。插件只有在 <plugins> 中定义时才会执行。有关详细信息,请参阅 this answer

但是,有些插件不需要在<plugins>中定义。这适用于 built-in lifecycle binding 的插件,例如 maven-jar-pluginmaven-resource-pluginmaven-compiler-plugin