1

Quite similar to Maven check that all dependencies have been released, Maven should also automatically check, that the version of the current version is not a SNAPSHOT.

What is the easiest way to do this?

gillesB
  • 1,061
  • 1
  • 14
  • 30
  • The current version should be a SNAPSHOT to create a release of it otherwise you already have a release ! – khmarbaise Apr 27 '23 at 10:58
  • 1
    @khmarbaise During the research for this I stumbled over the `maven-release-plugin`. Till now I made these steps manually, e.g. creating a release branch, updating the version etc. But I am taking a look at the `maven-release-plugin` atm. – gillesB Apr 27 '23 at 11:05

1 Answers1

0

It does not seem that the maven-enforcer-plugin provides a built-in rule for this task. Nevertheless the requireProperty can be configured to perform the check.

I put the following snippet in my release profile. The first execution checks that the project version does not contain the String SNAPSHOT. The second execution checks that no dependency is a SNAPSHOT version.

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-enforcer-plugin</artifactId>
  <version>3.3.0</version>
  <executions>
    <execution>
      <id>enforce-property</id>
      <goals>
        <goal>enforce</goal>
      </goals>
      <configuration>
        <rules>
          <requireProperty>
            <property>project.version</property>
            <message>"Project version must be specified."</message>
            <regex>^(?!.*SNAPSHOT).+$</regex>
            <regexMessage>"Project version must not contain -SNAPSHOT."</regexMessage>
          </requireProperty>
        </rules>
        <fail>true</fail>
      </configuration>
    </execution>
    <execution>
      <id>enforce-no-snapshots</id>
      <goals>
        <goal>enforce</goal>
      </goals>
      <configuration>
        <rules>
          <requireReleaseDeps>
            <message>No Snapshots Allowed!</message>
          </requireReleaseDeps>
        </rules>
        <fail>true</fail>
      </configuration>
    </execution>
  </executions>
</plugin>
gillesB
  • 1,061
  • 1
  • 14
  • 30