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?
DefaultBeanConfiguratoris 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
BeanConfiguratorand use reflection to get itsConverterLookup converterLookupfield, then callregisterConverterwith 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.