What is pluginManagement in Maven's pom.xml?

前端 未结 5 1096
野性不改
野性不改 2020-11-22 06:41

This is a snippet of my pom file.

....
        
            
                

        
相关标签:
5条回答
  • 2020-11-22 06:59

    pluginManagement: is an element that is seen along side plugins. Plugin Management contains plugin elements in much the same way, except that rather than configuring plugin information for this particular project build, it is intended to configure project builds that inherit from this one. However, this only configures plugins that are actually referenced within the plugins element in the children. The children have every right to override pluginManagement definitions.

    From http://maven.apache.org/pom.html#Plugin%5FManagement

    Copied from :

    Maven2 - problem with pluginManagement and parent-child relationship

    0 讨论(0)
  • 2020-11-22 07:07

    You use pluginManagement in a parent pom to configure it in case any child pom wants to use it, but not every child plugin wants to use it. An example can be that your super pom defines some options for the maven Javadoc plugin.

    Not each child pom might want to use Javadoc, so you define those defaults in a pluginManagement section. The child pom that wants to use the Javadoc plugin, just defines a plugin section and will inherit the configuration from the pluginManagement definition in the parent pom.

    0 讨论(0)
  • 2020-11-22 07:10

    The difference between <pluginManagement/> and <plugins/> is that a <plugin/> under:

    • <pluginManagement/> defines the settings for plugins that will be inherited by modules in your build. This is great for cases where you have a parent pom file.

    • <plugins/> is an actual invocation of the plugin. It may or may not be inherited from a <pluginManagement/>.

    You don't need to have a <pluginManagement/> in your project, if it's not a parent POM. However, if it's a parent pom, then in the child's pom, you need to have a declaration like:

    <plugins>
        <plugin>
            <groupId>com.foo</groupId>
            <artifactId>bar-plugin</artifactId>
        </plugin>
    </plugins>
    

    Notice how you aren't defining any configuration. You can inherit it from the parent, unless you need to further adjust your invocation as per the child project's needs.

    For more specific information, you can check:

    • The Maven pom.xml reference: Plugins

    • The Maven pom.xml reference: Plugin Management

    0 讨论(0)
  • 2020-11-22 07:17

    You still need to add

    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
        </plugin>
    </plugins>
    

    in your build, because pluginManagement is only a way to share the same plugin configuration across all your project modules.

    From Maven documentation:

    pluginManagement: is an element that is seen along side plugins. Plugin Management contains plugin elements in much the same way, except that rather than configuring plugin information for this particular project build, it is intended to configure project builds that inherit from this one. However, this only configures plugins that are actually referenced within the plugins element in the children. The children have every right to override pluginManagement definitions.

    0 讨论(0)
  • 2020-11-22 07:19

    So if i understood well, i would say that <pluginManagement> just like <dependencyManagement> are both used to share only the configuration between a parent and it's sub-modules.

    For that we define the dependencie's and plugin's common configurations in the parent project and then we only have to declare the dependency/plugin in the sub-modules to use it, without having to define a configuration for it (i.e version or execution, goals, etc). Though this does not prevent us from overriding the configuration in the submodule.

    In contrast <dependencies> and <plugins> are inherited along with their configurations and should not be redeclared in the sub-modules, otherwise a conflict would occur.

    is that right ?

    0 讨论(0)
提交回复
热议问题