Execute Maven plugin goal on child modules, but not on parent

后端 未结 6 899
眼角桃花
眼角桃花 2020-12-07 18:49

In a multi-module project, how can you specify that you want to execute a plugin goal in all the child-modules, but not on the parent project? There is

6条回答
  •  萌比男神i
    2020-12-07 18:58

    According to the Default Lifecycle Bindings, the bindings for a packaging pom are:

    Default Lifecycle Bindings - Packaging pom

    package       site:attach-descriptor  
    install       install:install  
    deploy        deploy:deploy
    

    So if your parent POM has a pom (this should be the case as pointed out in a comment) and if you bind your plugins to other phases than those above (see the Lifecycle Reference for a comprehensive list), they won't be executed during the build of the parent POM.

    (EDIT: My initial answer is just wrong. If you bind a plugin goal to a particular phase, it will be triggered during that phase, regardless of the packaging of the project. The Default Lifecycle Bindings don't have anything to do with that, they are just default lifecycle bindings. All what matters is if the phase to which the plugin is bound is part of the build lifecyle.)

    As you pointed out, you can use the pluginManagement in the parent pom for the configuration of the plugin but if you really want to execute a plugin goal in children modules and not in the parent (you might have good reasons to do this but most of time, plugins won't have much effet on a module with a pom packaging that doesn't have any content), you'll have to reference plugins in the plugins element in the children.

    Applied to your example, the parent pom.xml could define the following specifications:

    
      pom
      ...
      
        child
      
      ...
      
        
          
            
              org.apache.maven.plugins
              maven-jar-plugin
              2.2
              
                
                  my-execution-id
                  integration-test
                  
                    jar
                  
                
              
            
            ...
          
        
      
      ...
    
    

    And in every child pom.xml, only the following is required:

    
      ...
      
        ...
        
          
            org.apache.maven.plugins
            maven-jar-plugin
          
        
        ...
      
    
    

提交回复
热议问题