Add parameters to Maven Enforcer Rules called from the command line

JF Meier :

Following https://stackoverflow.com/a/59389998/927493, one can now call the Maven enforcer plugin from the command line.

This works well, but unfortunately I haven't understood yet whether I can set rule parameters through the command line. An example would be version in the RequireMavenVersion rule.

Robert Scholte :

No you can't. I'm actually not that happy with the current implementation because of these expectations. The first usecase was a simple, parameterless rule. Of course we could predict the next questions.

Let's first explain how "complex" plugin configuration works. Take a look at the following example:

<rules>
  <requireMavenVersion>
    <version/>
  </requireMavenVersion>
</rules>

Here requireMavenVersion is the lowercase classname in the same package as the EnforceMojo(or enforce goal), version is a setter on this class. What you see is nothing more than a Pojo. The only requirement here is that RequireMavenVersion implements the EnforcerRule interface, so Maven can call its execute method see:

 @Parameter
 private EnforcerRule[] rules;

If you want to call a rule from commandline, the plugin simple tries to rename the rule to a full qualified classname make a new instance of it. Next its execute method will be called.

The request for this feature was to enforce rules without touching the project. This should be solved as a Maven Extension, which fits much better to that usecase.

But in conclusion: no you can't.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=4279&siteId=1