问题描述
@Mojo(name = "generate",defaultPhase = LifecyclePhase.GENERATE_SOURCES,threadSafe = true)
public class GraphQLCodegenMojo extends AbstractMojo {
@Parameter
private Map<String,String> customTypesMapping;
}
我通常以以下方式设置(基于Maven guide):
<customTypesMapping>
<DateTime>java.util.Date</DateTime>
</customTypesMapping>
我尝试了不同的方法,但是它们都不起作用:
<customTypesMapping>
<DateTime!>java.util.Date</DateTime!>
<DateTime!>java.util.Date</DateTime!>
<customTypeMapping>
<name>DateTime</key>
<value>java.util.Date</value>
</customTypeMapping>
</customTypeMapping>
是否存在向后兼容的方式来更改我的Maven插件(不破坏现有客户端)?
解决方法
解决方案是使用java.util.Properties
:
@Mojo(name = "generate",defaultPhase = LifecyclePhase.GENERATE_SOURCES,threadSafe = true)
public class GraphQLCodegenMojo extends AbstractMojo {
@Parameter
private Properties customTypesMapping = new Properties();
通过这种方式,可以通过两种方式在xml中进行指定:
<customTypesMapping>
<property>
<!--note the special character below-->
<name>Date!</name>
<value>java.util.Date</value>
</property>
</customTypesMapping>
并以向后兼容的方式,使该插件的现有用户无需更改其配置:
<customTypesMapping>
<DateTime>java.util.Date</DateTime>
</customTypesMapping>