Where should the maven-compiler-plugin declaration be placed: in <plugins> or <pluginManagement>?
I have a multi-module maven project and I want to force all my submodules to use the maven-compiler-plugin specified in the pom.xml root directory. Where should I place the maven-compiler-plugin declaration (in the pom.xml root directory): in the <plugins> section or in the <pluginManagement> section? The question also applies to maven-release-plugin .
These 2 sections ( plugins and pluginManagement ) have slightly different goals.
The first ( plugins ) is used to indicate the build process of your project (and all child projects that inherit from the parent project). If you include some plugin in this section, it will be executed in each child project, regardless of its type.
The second ( pluginManagement ) is used to specify general plug-in parameters for all projects that inherit from the parent project (for example, plug-in version and configuration).
Speaking of 2 plugins you mentioned. maven-compiler-plugin is the default plugin that will run regardless of whether you specify it or not. It makes sense to include it in pluginManagement and indicate its configuration there. maven-release-plugin , however, is by default not tied to any phase of the life cycle. Therefore, if you want it to run in all of your child projects, you need to add it to the plugins section.
It depends on what you need. If you include them in the plugins section, they will run for all POMs ... including the parent. If you want child POMs to fulfill the goals of the plugin, you must put them under pluginManagement . However, in this case, you will need to include them in each child POM.
However, the easiest way is to try plugins first. If there is no build failure, then you are well off. Otherwise, you will need to move some or all of it to pluginManagement .