Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where should be placed maven-compiler-plugin declaration: in <plugins> or <pluginManagement>?

Tags:

java

maven

I have a multi-module maven project, and I want to cause all my submodules to use maven-compiler-plugin specified in root pom.xml. Where I should place maven-compiler-plugin declaration (in root pom.xml): in <plugins> section or in <pluginManagement> section? Question also relates to maven-release-plugin too.

like image 895
WelcomeTo Avatar asked Dec 19 '12 19:12

WelcomeTo


2 Answers

These 2 sections (plugins and pluginManagement) have slightly different purposes.

The first one (plugins) is used to specify the build process of your project (and all of the child projects that inherit from the parent project). If you include some plugin into this section, it will be executed in each of the child projects regardless of its type.

The second one (pluginManagement) is used to specify common plugin settings for all of the projects that inherit from the parent project (for example, plugin version and configuration).

Speaking of the 2 plugins that you've mentioned. maven-compiler-plugin is a default plugin that will be executed whether you specify it or not. It makes sense to include it in pluginManagement and specify its configuration there. maven-release-plugin, however, is not bound to any lifecycle phase by default. So if you'd like it to be executed in all of your child projects, you'll have to add it to plugins section.

like image 77
Andrew Logvinov Avatar answered Sep 22 '22 12:09

Andrew Logvinov


It depends on what you're after. If you include them under the plugins section, they will execute for all POMs...including the parent. If you only want child POMs to execute the plugin goals, then you should place them under pluginManagement. However, in that case, you will have to enable them in each child POM.

That said, the easiest thing to do is try under plugins first. If there's no build failure, then you're good to go. Otherwise, you will need to move some or all over to pluginManagement.

like image 36
stevevls Avatar answered Sep 19 '22 12:09

stevevls