8

As part of my release process, I use mvn versions:use-releases goal to replace all -SNAPSHOT dependencies with released versions. After this, I want to check if all the SNAPSHOT dependencies have been replaced with releases or not.

Question: How can I check it?

I know, the maven release plugin performs such a check as part of release-prepare goal, but I don't want to use release plugin.

A_Di-Matteo
  • 26,902
  • 7
  • 94
  • 128
Mikhail Chibel
  • 1,865
  • 1
  • 22
  • 34

2 Answers2

10

You can use the maven-enforcer-plugin to double check whether any SNAPSHOT dependency is still there or not.

From the official example of its requireReleaseDeps rule:

<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-enforcer-plugin</artifactId>
        <version>1.4.1</version>
        <executions>
          <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>
    </plugins>
  </build>
  [...]
</project>

Note the fail element set to true, in this case the build would fail if any SNAPSHOT dependency was found.

You could place such configuration in a maven profile and activate it when required (hence whenever this check must be performed).

A_Di-Matteo
  • 26,902
  • 7
  • 94
  • 128
  • 8
    You can also run this as a one-off from the command line with `mvn enforcer:enforce -Drules=requireReleaseDeps` – Ivan G. Jan 11 '21 at 15:34
0

The requireReleaseDeps built-in rule of the maven-enforcer-plugin does not apply for dependencies of plugins. It is a quite rare case, but plugins can carry their own dependencies to augment their default behaviour.

If someone is interested in checking for SNAPSHOT dependencies of plugins, configure the maven-enforcer-plugin in this way:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-enforcer-plugin</artifactId>
    <version>3.0.0</version>
    <executions>
        <execution>
            <id>enforce-no-snapshots</id>
            <goals>
                <goal>enforce</goal>
            </goals>
            <configuration>
                <rules>
                    <!-- Add this rule (don't forget the 'implementation' hint! ) -->
                    <requireReleaseDepsInPlugins implementation="org.apache.maven.enforcer.rule.requireReleaseDepsInPlugins" />
                </rules>
                <fail>true</fail>
            </configuration>
        </execution>
    </executions>
    <dependencies>
        <!-- Add this dependency to the plugin -->
        <dependency>
            <groupId>io.github.thefolle</groupId>
            <artifactId>glowing-waffle</artifactId>
            <version>1.2.0</version>
        </dependency>
    </dependencies>
</plugin>

glowing-waffle is a collection of custom rules for the enforcer plugin. It defines the requireReleaseDepsInPlugins rule.

Davide Calarco
  • 432
  • 4
  • 6