I need to use custom type, e.g., LunarDate
, in my Mojo object:
class MyMojo extends AbstractMojo {
/** @parameter */
LunarDate lunarDate;
}
And I want to configure the parameter in <configuration>
section in pom.xml.
<configuration>
<lunarDate>丁丑年二月初四</lunarDate>
</configuration>
(The type LunarDate
is just an example to illustrate the question)
I've already had the type converters, but how to enable them?
DefaultBeanConfigurator
is responsible for usingDefaultConverterLookup
, and it instantiates it directly without using the Plexus Container.You could I suppose copy and modify it in a build extension, but registering your copy via
@Component(role=BeanConfigurator.class)
will likely have no effect; I have tried replacing standard Maven components in the past from build extensions and been told on maven-dev that it is not possible.You could look up the default
BeanConfigurator
and use reflection to get itsConverterLookup converterLookup
field, then callregisterConverter
with your custom convertor, but this would be fragile.Probably best is to just give up, declare your Mojo parameter to be of type
String
, and do the conversion explicitly inexecute
.For newer Maven (tested with Maven 3.3.1) you can now subclass
BasicComponentConfigurator
to access theDefaultConverterLookup
as a member variable:Then in the pom.xml enable the generation of plexus meta data: