项目上线之前必须排除所有SNAP-SHOT版本的依赖 并全部升级为RELEASE版本,手工一个一个去排效率太低,Maven提供了maven-enforcer-plugin插件来做这件事情。
Require Release Dependencies
This rule checks the dependencies and fails if any snapshots are found.
The following parameters are supported by this rule:
- searchTransitive - if transitive dependencies should be checked.
Default: true - message - an optional message to the user if the rule fails.
- onlyWhenRelease - if this rule should only be executed when the
version is a non-SNAPSHOT version. Default: false - failWhenParentIsSnapshot - if the parent should be checked. Default:
true - includes - List of dependency patterns to include when checking for
snapshot versions - excludes - List of dependency patterns to exclude when checking for
snapshot versions
1.Sample Plugin Configuration:
<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>
2.Includes/Excludes Plugin Configuration:
<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>
<excludes>
<exclude>org.apache.maven:maven-core</exclude>
<exclude>org.apache.maven.plugins:*</exclude>
</excludes>
</requireReleaseDeps>
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
[...]
</project>
参考
Require Release Dependencies:http://maven.apache.org/enforcer/enforcer-rules/requireReleaseDeps.html