How to define a default mojo for a maven plugin

前端 未结 2 540
别那么骄傲
别那么骄傲 2020-12-17 20:23

I\'ve written a plugin that generate one file in target/generated-sources/. This plugin only has one mojo. This mojo is declared with the following :

/**
 *          


        
2条回答
  •  囚心锁ツ
    2020-12-17 21:02

    Having your Maven plugin automatically run its default goal when its default phase executes is not possible. This is confusing because there are a lot of standard plugin ‘bindings’ for specific packagings. Those are defined in Maven core: https://maven.apache.org/ref/3.6.1/maven-core/default-bindings.html

    For example, for WAR packaging it is:

    
      
        org.apache.maven.plugins:maven-resources-plugin:2.6:resources
      
      
        org.apache.maven.plugins:maven-compiler-plugin:3.1:compile
      
      
        org.apache.maven.plugins:maven-resources-plugin:2.6:testResources
      
      
        org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile
      
      
        org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test
      
      
        org.apache.maven.plugins:maven-war-plugin:2.2:war
      
      
        org.apache.maven.plugins:maven-install-plugin:2.4:install
      
      
        org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy
      
    
    

    By defining a default phase in your plugin you won’t have to specify that, just the goal. In your case:

    
        
            convert
            
            
                convertsql
            
        
    
    

    Also see https://maven.apache.org/developers/mojo-api-specification.html (look for @phase). The relevant quote (my emphasis):

    Defines a default phase to bind a mojo execution to if the user does not explicitly set a phase in the POM. Note: This annotation will not automagically make a mojo run when the plugin declaration is added to the POM. It merely enables the user to omit the element from the surrounding element.

提交回复
热议问题