0

As per this answer I was trying to avoid snapshot artefacts by <enabled>false</enabled> but maven still downloads the artefacts from snapshot repo and don't fail the build.

<repositories>
    <repository>
        <id>s3-snapshot</id>
        <url>s3://my_url/snapshot</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>

What can be best way to enforce maven to not use snapshot artefacts ?

Rahul Kotwal
  • 3
  • 1
  • 3

1 Answers1

2

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
glytching
  • 44,936
  • 9
  • 114
  • 120
  • Thanks @glytching, could you please assist me, how could I make this rule conditional e.g. I want to run this rule only if cmd-line param `-DisRelease=true` – Rahul Kotwal Feb 19 '18 at 10:49