0

In my parent POM, I defined a dependency plugin with phase prepare-package inside <pluginManagement><plugins>.

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

In my child POM, I didn't specify any dependency plugin. It didn't get executed. I have to put this in <plugins> to get it to trigger:

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

The Maven goals I'm using are clean install.

My question is, why do I have to explicitly specify maven-dependency-plugin again in my child POM?

  1. Other plugins like maven-jar-plugin, maven-resource-plugin, maven-compiler-plugin are running even though I didn't re-declare them in my POM. Why is it inconsistent?
  2. dependency's phase was configured as prepare-package, which is before package phase in the Maven lifecycle, hence I presume it should have been "executed in the order given up to the point of the one specified". But it isn't, why?

Thanks in advance to anyone who is able to help with my enquiries! :)

Cardin
  • 5,148
  • 5
  • 36
  • 37
  • Does this answer your question? [What is pluginManagement in Maven's pom.xml?](https://stackoverflow.com/questions/10483180/what-is-pluginmanagement-in-mavens-pom-xml) – Roland Weisleder Apr 30 '20 at 05:39
  • No it does not answer why some plugins can trigger, while some can't, even though all of them are inside – Cardin Apr 30 '20 at 05:42
  • 1
    These plugins are part of the [built-in lifecycle bindings](http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Built-in_Lifecycle_Bindings). – Roland Weisleder Apr 30 '20 at 05:44
  • 1
    Thanks, both your comments have together managed to answer my question. If you want you can create an answer. – Cardin Apr 30 '20 at 05:49

1 Answers1

2

The section <pluginManagement> is used to share plugin configurations between this project and child projects. Plugins are only executed if they are defined in <plugins>. See this answer for more information.

However, some plugins don't need to be defined in <plugins>. This applies to plugins of the built-in lifecycle binding like maven-jar-plugin, maven-resource-plugin and maven-compiler-plugin.

Roland Weisleder
  • 9,668
  • 7
  • 37
  • 59