简体   繁体   English

将参数添加到从命令行调用的 Maven Enforcer Rules

[英]Add parameters to Maven Enforcer Rules called from the command line

Following https://stackoverflow.com/a/59389998/927493 , one can now call the Maven enforcer plugin from the command line.https://stackoverflow.com/a/59389998/927493之后,现在可以从命令行调用 Maven 执行器插件。

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.一个例子是RequireMavenVersion规则中的version

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.这里 requireMavenVersion 是与 EnforceMojo(或enforce目标)在同一个包中的小写类名,version 是这个类的一个 setter。 What you see is nothing more than a Pojo.你所看到的只不过是一个 Pojo。 The only requirement here is that RequireMavenVersion implements the EnforcerRule interface, so Maven can call its execute method see:这里唯一的要求是 RequireMavenVersion 实现了 EnforcerRule 接口,所以 Maven 可以调用它的execute方法见:

 @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.如果您想从命令行调用规则,插件 simple 会尝试将规则重命名为完全限定的类名,并为其创建一个新实例。 Next its execute method will be called.接下来将调用它的 execute 方法。

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.这应该作为 Maven 扩展来解决,它更适合该用例。

But in conclusion: no you can't.但总而言之:不,你不能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM