How can a Maven plugin Mojo parameter be configured so that the default value is an empty String?
The defaultValue
property of the Parameter
annotation already defaults to ""
, so configuring the parameter like @Parameter(defaultValue = "")
is equivalent to not configuring it at all.
This does not work and produces a null value at runtime:
@Parameter(defaultValue = "")
public String myParam;
The field can be initialized with an empty string to avoid a null value at runtime, while still allowing the user to override it:
@Parameter
public String myParam = "";
The only caveat appears to be that this will not appear in documentation generated by the site plugin as a default value