In answer to this question:
What can be best way to enforce maven to not use snapshot artefacts ?
The Maven Enforcer Plugin's requireReleaseDeps rule fails a build if any snapshot versions are found in your projects dependencies.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0-M1</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>
Update in reply to this:
how could I make this rule conditional e.g. I want to run this rule only if cmd-line param -DisRelease=true
Just move the plugin definition under a profile, for example ...
<profiles>
<profile>
<id>release</id>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0-M1</version>
...
</plugin>
</plugins>
</profile>
</profiles>
... then execute it as follows:
mvn clean install -Prelease