您的位置:首页 > 其它

Maven 工程规范

2015-10-19 20:28 274 查看

SuperPom继承


所有工程需直接或间接继承 SuperPom

<parent>
<artifactId>qunar-supom</artifactId>
<groupId>qunar.common</groupId>
<version>1.3.2</version>
</parent>



避免使用默认profile,不要出现以下代码


<activation>
<activeByDefault>true</activeByDefault>
</activation>



WAR工程忽略deploy


<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>



重复类检查


1. 增加超级pom指向

<parent>
<groupId>qunar.common</groupId>
<artifactId>qunar-supom-generic</artifactId>
<version>1.3.2</version>
</parent>


2. 运行命令查看重复类

mvn enforcer:enforce


3. 常见重复类排除

junit :jmockit 冲突问题: 请将 junit 换成 junit-dep
commons-beanutils & commons-collections 冲突问题: 去掉commons-beanutils版本号
jcl-over-slf4j & commons-logging 冲突: 删掉 commons-logging


版本号管理


所有依赖的版本号应使用dependencyManagement 显示管理. dependency中不能包含版本号

<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.qunar.rpc.demo</groupId>
<artifactId>rpc-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.qunar.rpc.demo</groupId>
<artifactId>rpc-api</artifactId>
</dependency>
</dependency>



Scope定义


应明确定义除了compile之外的scope. 尤其是test. 作用域参考下表

scope编译测试运行举例
compileYYYspring-core
test-Y-JUnit
providedYY-servlet-api
runtime-YYJDBC驱动
systemYY-本地JNI相关,禁止使用

解决包冲突问题,使用搜索引擎


http://mvnrepository.com/

Jar 禁止包含工程配置文件


默认的屏蔽的文件有: *.xml, *.properties

Resource 继承与重载


1. 配置文件中各环境差异的放在profile中, 否则放在resource里.

2. 建议使用Spring的变量替换 , 禁用maven替换.

请慎用 combine.self="override"


DupplicateClass 解决汇总

Found in:
org.slf4j:slf4j-log4j12:jar:1.6.1:compile
org.slf4j:slf4j-jdk14:jar:1.6.1:compile
Duplicate classes:
org/slf4j/impl/StaticMarkerBinder.class
org/slf4j/impl/StaticLoggerBinder.class
org/slf4j/impl/StaticMDCBinder.class


解决方案 : 删掉 slf4j-jdk14:jar

原因: 这是分别两个slf4j的实现, 按标准选择 log4j实现.

Found in:
commons-beanutils:commons-beanutils:jar:1.8.2:compile
commons-beanutils:commons-beanutils-core:jar:1.7.0:compile
Duplicate classes:
org/apache/commons/beanutils/locale/LocaleBeanUtilsBean.class
org/apache/commons/beanutils/locale/converters/DoubleLocaleConverter.class
org/apache/commons/beanutils/locale/converters/DecimalLocaleConverter.class
org/apache/commons/beanutils/converters/ShortConverter.class


解决方案 : 删掉 commons-beanutils-core:jar, 并且采用beanutils的继承版本号.

原因: commons-beanutils-core:jar 是个有问题的包, 只删除了一部分外部依赖, 并没有彻底删掉外部包. 所以, 使用我们打过补丁的beanutils.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: