【问题标题】:Fail Maven build if Maven property is not aligned to convention如果 Maven 属性不符合约定,则 Maven 构建失败
【发布时间】:2021-04-02 18:20:15
【问题描述】:

Java 存储库的pom.xml 中的 Maven 属性必须与某些约定保持一致,CI 流程才能正常工作。

例如:

<app-name.prop-name-version>X.X.X.X</app-name-version.prop-name-version>

如果 maven 属性不符合约定,有没有办法使 maven 构建失败?

我想过从头开始开发maven插件,但是还有其他方法吗?

【问题讨论】:

  • 为什么你有一个 ci 需要的属性?你能解释一下究竟需要什么吗?

标签: java maven maven-plugin


【解决方案1】:

Maven Enforcer Plugin 正是您所需要的。这有很多内置规则,例如 Require Property 根据documentation,此规则可以强制设置声明的属性,并且可以选择适合正则表达式规则。

<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-enforcer-plugin</artifactId>
        <version>3.0.0-M3</version>
        <executions>
          <execution>
            <id>enforce-property</id>
            <goals>
              <goal>enforce</goal>
            </goals>
            <configuration>
              <rules>
                <requireProperty>
                  <property>app-name.prop-name-version</property>
                  <message>"Project version must be specified."</message>
                  <regex>.*[...]$</regex>
                  <regexMessage>"Invalid format."</regexMessage>
                </requireProperty>
              </rules>
              <fail>true</fail>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  [...]
</project>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-11-26
    • 2012-08-05
    • 1970-01-01
    • 2011-01-22
    • 2018-05-15
    • 1970-01-01
    • 2021-07-02
    相关资源
    最近更新 更多