Chinaunix首页 | 论坛 | 博客
  • 博客访问: 135837
  • 博文数量: 48
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 200
  • 用 户 组: 普通用户
  • 注册时间: 2013-05-21 14:51
个人简介

天不设牢,二人自在心中舍牢。顺天而行者,心中无牢。

文章分类

全部博文(48)

文章存档

2013年(48)

我的朋友

分类: Web开发

2013-08-21 11:10:53

转自:http://zhwj184.iteye.com/blog/1528627
你如果想再maven中定义一些配置,这些配置需要整个团队遵守,比如定义maven版本,java版本,os配置,文件系统的配置,或者你想扩展的任何配置,那么就可以使用Maven Enforcer Plugin这个maven插件。

 

pom中引入Maven Enforcer Plugin插件。

Java代码  收藏代码
  1.   
  2.   ...  
  3.     
  4.       
  5.       
  6.         
  7.           
  8.           org.apache.maven.plugins  
  9.           maven-enforcer-plugin  
  10.           1.0.1  
  11.           
  12.         ...  
  13.         
  14.       
  15.       
  16.       
  17.         
  18.         org.apache.maven.plugins  
  19.         maven-enforcer-plugin  
  20.         1.0.1  
  21.         
  22.       ...  
  23.       
  24.     
  25.   ...  
  26.   

 

 

在执行mvn clean package时会默认执行这个插件,如果只想运行这个插件可以直接mvn ,mvn ,mvn ,可以参考

 

比如我们如果想指定maven和java的版本,则配置如下:

Java代码  收藏代码
  1.   
  2.   [...]  
  3.     
  4.       
  5.         
  6.         org.apache.maven.plugins  
  7.         maven-enforcer-plugin  
  8.         1.0.1  
  9.           
  10.             
  11.             enforce-versions  
  12.               
  13.               enforce  
  14.               
  15.               
  16.                 
  17.                   
  18.                   2.0.6  
  19.                   
  20.                   
  21.                   1.5  
  22.                   
  23.                   
  24.                   unix  
  25.                   
  26.                 
  27.               
  28.             
  29.           
  30.         
  31.       
  32.     
  33.   [...]  
 

 

如果为了提高执行速度,不想运行这个插件,则可以通过-Denforcer.skip=true或者简单的-Dskip=true就可以跳过这个这个插件的运行。如果mvn package过程中出现有关这个插件的异常,则可以简单通过这个参数跳过这个验证。

 

这个插件默认提供的规则有:

 

Java代码  收藏代码
  1. alwaysPass - Always passes... used to test plugin configuration.  
  2. alwaysFail - Always fail... used to test plugin configuration.  
  3. bannedDependencies - enforces that excluded dependencies aren't included.  
  4. bannedPlugins - enforces that excluded plugins aren't included.  
  5. dependencyConvergence - ensure all dependencies converge to the same version.  
  6. evaluateBeanshell - evaluates a beanshell script.  
  7. requireReleaseDeps - enforces that no snapshots are included as dependencies.  
  8. requireReleaseVersion - enforces that the artifact is not a snapshot.  
  9. requireMavenVersion - enforces the Maven version.  
  10. requireJavaVersion - enforces the JDK version.  
  11. requireOS - enforces the OS / CPU Archictecture.  
  12. requirePluginVersions - enforces that all plugins have a specified version.  
  13. requireProperty - enforces the existence and values of properties.  
  14. requireFilesDontExist - enforces that the list of files do not exist.  
  15. requireFilesExist - enforces that the list of files do exist.  
  16. 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

还有一篇文章可以参考:

阅读(1113) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~