Unknown elements in the maven configuration section of the plugin should lead to errors instead of silently ignoring the parameter (as would be the default). Here is example code how this could be done:
@Mojo(name = "check-config", defaultPhase = LifecyclePhase.VALIDATE)
public class CheckConfigMojo extends AbstractMojo {
@Parameter(property = "myplugin.someParam")
private String someParam;
@Component
private MavenProject project;
@Parameter(defaultValue = "${mojoExecution}", readonly = true)
private MojoExecution mojoExecution;
public void execute() throws MojoExecutionException {
Set<String> knownParams = Arrays.stream(this.getClass().getDeclaredFields())
.filter(f -> f.isAnnotationPresent(Parameter.class))
.map(Field::getName)
.collect(Collectors.toSet());
Xpp3Dom cfg = (Xpp3Dom) mojoExecution.getConfiguration();
if (cfg != null) {
for (Xpp3Dom child : cfg.getChildren()) {
if (!knownParams.contains(child.getName())) {
getLog().warn("Unknown configuration parameter: " + child.getName());
}
}
}
}
}
Unknown elements in the maven configuration section of the plugin should lead to errors instead of silently ignoring the parameter (as would be the default). Here is example code how this could be done: