Custom type converter for Mojo configuration?

后端 未结 3 884
刺人心
刺人心 2021-01-23 16:04

I need to use custom type, e.g., LunarDate, in my Mojo object:

class MyMojo extends AbstractMojo {

    /** @parameter */
    LunarDate lunarDate;

         


        
3条回答
  •  北恋
    北恋 (楼主)
    2021-01-23 16:26

    For newer Maven (tested with Maven 3.3.1) you can now subclass BasicComponentConfigurator to access the DefaultConverterLookup as a member variable:

    @Component(role = ComponentConfigurator.class, hint = "basic")
    public class ExtendedComponentRegistrator 
            extends BasicComponentConfigurator  
            implements Initializable {
    
        @Override
        public void initialize() throws InitializationException {
            converterLookup.registerConverter(new MyCustomConverter());
        }
    }
    

    Then in the pom.xml enable the generation of plexus meta data:

    
      org.codehaus.plexus
      plexus-component-metadata
      
        
          
            generate-metadata
          
        
      
    
    

提交回复
热议问题