Optimal Maven Plugin configuration


May 26, 2008 By Brian Fox

Maven has two sections in the pom relating to plugin configuration: project.build.plugins and project.build.pluginManagment.plugins. These two sections are unfortunately often confused and misused.

PluginManagement is similar to dependencyManagment in that it provides configuration and defaults for plugins if they are used in the build. This is where we recommend you lock down your plugin versions, but it also allows default configuration.

The regular plugins section also allows the version and default configuration to be defined, and this is where the confusion lies. It is technically valid to define the plugin version and default configuration here, but I find it easier to grok the pom when following this guideline:

  • If the plugin block is not defining an execution (and thus binding maven to do something in the lifecycle), put that block in pluginManagment

This means that configuration for plugins brought in by the default lifecycle such as resources, compiler, jar, etc will almost always go in the pluginManagement section. Doing so tends to keep your regular plugins section rather small and only showing the config for plugins that are doing additional things during the lifecycle.

Following the above defined guideline will also have you locating the config for plugins that are primarily run from the command line in pluginManagment…again keeping the plugins section clean and concise.