转自:http://zhwj184.iteye.com/blog/1528627
你如果想再maven中定义一些配置,这些配置需要整个团队遵守,比如定义maven版本,java版本,os配置,文件系统的配置,或者你想扩展的任何配置,那么就可以使用Maven Enforcer Plugin这个maven插件。
pom中引入Maven Enforcer Plugin插件。
-
-
...
-
-
-
-
-
-
org.apache.maven.plugins
-
maven-enforcer-plugin
-
1.0.1
-
-
...
-
-
-
-
-
-
org.apache.maven.plugins
-
maven-enforcer-plugin
-
1.0.1
-
-
...
-
-
-
...
-
在执行mvn clean package时会默认执行这个插件,如果只想运行这个插件可以直接mvn ,mvn ,mvn ,可以参考
比如我们如果想指定maven和java的版本,则配置如下:
-
-
[...]
-
-
-
-
org.apache.maven.plugins
-
maven-enforcer-plugin
-
1.0.1
-
-
-
enforce-versions
-
-
enforce
-
-
-
-
-
2.0.6
-
-
-
1.5
-
-
-
unix
-
-
-
-
-
-
-
-
-
[...]
如果为了提高执行速度,不想运行这个插件,则可以通过-Denforcer.skip=true或者简单的-Dskip=true就可以跳过这个这个插件的运行。如果mvn package过程中出现有关这个插件的异常,则可以简单通过这个参数跳过这个验证。
这个插件默认提供的规则有:
-
alwaysPass - Always passes... used to test plugin configuration.
-
alwaysFail - Always fail... used to test plugin configuration.
-
bannedDependencies - enforces that excluded dependencies aren't included.
-
bannedPlugins - enforces that excluded plugins aren't included.
-
dependencyConvergence - ensure all dependencies converge to the same version.
-
evaluateBeanshell - evaluates a beanshell script.
-
requireReleaseDeps - enforces that no snapshots are included as dependencies.
-
requireReleaseVersion - enforces that the artifact is not a snapshot.
-
requireMavenVersion - enforces the Maven version.
-
requireJavaVersion - enforces the JDK version.
-
requireOS - enforces the OS / CPU Archictecture.
-
requirePluginVersions - enforces that all plugins have a specified version.
-
requireProperty - enforces the existence and values of properties.
-
requireFilesDontExist - enforces that the list of files do not exist.
-
requireFilesExist - enforces that the list of files do exist.
-
requireFilesSize - enforces that the list of files exist and are within a certain size range.
可以参考:
当然你可以扩展自定义的规则:http://maven.apache.org/enforcer/enforcer-api/writing-a-custom-rule.html
还有一篇文章可以参考:
阅读(1164) | 评论(0) | 转发(0) |