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

Categories

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?


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

1 Answer

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...