7

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.

WelcomeTo
  • 19,843
  • 53
  • 170
  • 286

2 Answers2

14

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.

Andrew Logvinov
  • 21,181
  • 6
  • 52
  • 54
  • thank you for clear answer. Can you explain me, why `maven-compiler-plugin` not executed by default in contrast to `maven-release-plugin` ? Or where I can see list of plugins executed by default during lifecycle phases? – WelcomeTo Dec 19 '12 at 19:37
  • You're welcome. List of default plugins and their goals depends on the project packaging. You can read more about it [here](http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Built-in_Lifecycle_Bindings) (actually, the whole page is worth reading). – Andrew Logvinov Dec 19 '12 at 19:40
  • Also what about `maven-surfire-plugin`? After your explanation I think it should be placed inside pluginManagement, because it bounded to "test" phases of maven..it's true? – WelcomeTo Dec 19 '12 at 19:41
  • Yes, it's true. `surefire` is a default plugin to run tests so it makes sense to put it to `pluginManagement`. – Andrew Logvinov Dec 19 '12 at 19:42
1

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.

stevevls
  • 10,675
  • 1
  • 45
  • 50
  • So inside `` section (in case of root's pom.xml) we can decalre all plugins which we need in submodules (without explicitly sprcifying them in submodules). And inside `` we declare only plugins _configuration_ (e.g. version), and we still need to declare them in submodules? – WelcomeTo Dec 19 '12 at 19:27