Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
148 views
in Technique[技术] by (71.8m points)

java - Fail Maven build if Maven property is not aligned to convention

Maven properties in pom.xml of Java repos have to be aligned to some convention for CI processes to work correctly.

For example:

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

Is there a way to fail maven builds if maven property is not aligned to convention?

I thought about developing maven plugin from scratch, but is there another way?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Maven Enforcer Plugin exactly does what you need. That has a lot of built-in rules like Require Property According the documentation this rule can enforce the declared property is set and optionally fits for a regex rule.

<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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...