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! :)

4
  • Does this answer your question? What is pluginManagement in Maven's pom.xml? Commented Apr 30, 2020 at 5:39
  • No it does not answer why some plugins can trigger, while some can't, even though all of them are inside <pluginManagement> Commented Apr 30, 2020 at 5:42
  • 2
    These plugins are part of the built-in lifecycle bindings. Commented Apr 30, 2020 at 5:44
  • 1
    Thanks, both your comments have together managed to answer my question. If you want you can create an answer. Commented Apr 30, 2020 at 5:49

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks for explaining why some plugins do not need to be mentioned in child projects, as well as the link that points out that groupId has also to be defined for all the other plugins (artifactId is not enough, and it won't complain)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.