0

I have the following property in my Maven MOJO plugin:

@Mojo(name = "generate", defaultPhase = LifecyclePhase.GENERATE_SOURCES, threadSafe = true)
public class GraphQLCodegenMojo extends AbstractMojo {
    @Parameter
    private Map<String, String> customTypesMapping;
}

Which I usually set in the following way (based on the Maven guide):

<customTypesMapping>
     <DateTime>java.util.Date</DateTime>
</customTypesMapping>

Now I want to allow plugin users to supply special characters as a map key.

I've tried different approaches, but neither of them work:

<customTypesMapping>
    <DateTime!>java.util.Date</DateTime!>
    <DateTime&#33;>java.util.Date</DateTime&#33;>
    <customTypeMapping>
        <name>DateTime</key>
        <value>java.util.Date</value>
    </customTypeMapping>
</customTypeMapping>

Is there a backward-compatible way to change my maven plugin (not breaking existing clients)?

Bogdan Kobylynskyi
  • 1,150
  • 1
  • 12
  • 34

1 Answers1

1

The solution is to use java.util.Properties:

@Mojo(name = "generate", defaultPhase = LifecyclePhase.GENERATE_SOURCES, threadSafe = true)
public class GraphQLCodegenMojo extends AbstractMojo {
    @Parameter
    private Properties customTypesMapping = new Properties();

In this way, it is possible to specify it in xml in 2 ways:

<customTypesMapping>
    <property>
        <!--note the special character below-->
        <name>Date!</name>
        <value>java.util.Date</value>
    </property>
</customTypesMapping>

and in a backwards-compatible way so that existing users of the plugin won't need to change their configuration:

<customTypesMapping>
    <DateTime>java.util.Date</DateTime>
</customTypesMapping>
Bogdan Kobylynskyi
  • 1,150
  • 1
  • 12
  • 34