【问题标题】:Maven Enforcer - Is it possible to have a custom rule with an array property?Maven Enforcer - 是否可以有一个带有数组属性的自定义规则?
【发布时间】:2023-03-06 14:56:02
【问题描述】:

我在配置我的一个强制执行器自定义规则时遇到问题。

我的 POM 文件中的插件配置如下所示:

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-enforcer-plugin</artifactId>
        <version>1.3.1</version>
        <executions>
          <execution>
            <id>enforce</id>
            <phase>validate</phase>
            <goals>
              <goal>enforce</goal>
            </goals>
            <configuration>
              <rules>
                <uTF8Rule implementation="com.mavenrules.utf8validator.UTF8Rule">
                  <validationPath>${basedir}</validationPath>
                </uTF8Rule>
              </rules>
            </configuration>
          </execution>
        </executions>
      </plugin>

已经在父 POM 中声明了对规则的依赖。

我想要的是能够将路径列表/数组指定为“uTF8Rule”的属性,而不仅仅是一个简单的变量。 (我希望 POM 负责我的规则适用的路径,而不是将规则配置为在我的 basedir 中搜索各种路径

我无法找到有关规则属性类型的参考/文档。

所需的输出类似于:

<configuration>
  <rules>
    <uTF8Rule implementation="com.mavenrules.utf8validator.UTF8Rule">
       <listOfPaths>
          <path1>xxx</path1>
          <path2>yyy</path2>                
       </listOfPaths>
    </uTF8Rule>
  </rules>
</configuration>

欢迎任何想法。

提前致谢!

【问题讨论】:

    标签: java maven maven-3 maven-plugin maven-enforcer-plugin


    【解决方案1】:

    配置中的对象遵循 JavaBean/pojo 约定。 所以在这种情况下:

    public class com.mavenrules.utf8validator.UTF8Rule {
      private List<String> listOfPaths; // or String[]
    }
    

    这应该已经足够了,但是有点没用。通过添加 getter 和 setter 你应该没问题。 如果我调用正确,某些版本在启动 List 或数组时会遇到问题,但您也可以自己做。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-23
      • 2020-12-15
      • 2021-02-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-08
      • 2015-09-18
      • 1970-01-01
      相关资源
      最近更新 更多