Learing Maven 3 - Optimizing and Refactoring POMs


一、Optimizing Dependencies

(1) You should create a property called AAA.BBB.CCC.version to share the version if some dependency versons are the same. For example,Both thehibernate-annotations andhibernate-commons-annotations are components of the same project released by JBoss, and so when there is a new project release, both of these dependencies will change.So the versions of hibernate-annotations and hibernate-commons-annotations should the same.

<project>
  ...
    <dependencies>
      <dependency>
	<groupId>org.hibernate</groupId>
	<artifactId>hibernate-annotations</artifactId>
	<version>3.3.0.ga</version>
      </dependency>
      <dependency>
	<groupId>org.hibernate</groupId>
	<artifactId>hibernate</artifactId>
	<version>3.3.0.ga</version>
      </dependency>
  </dependencies>
...

It shoule be:

<project>
  ...
  <properties>
    <hibernate.annotations.version>3.3.0.ga</hibernate.annotations.version>
  </properties>

    <dependencies>
      <dependency>
	<groupId>org.hibernate</groupId>
	<artifactId>hibernate-annotations</artifactId>
	<version>${hibernate.annotations.version}</version>
      </dependency>
      <dependency>
	<groupId>org.hibernate</groupId>
	<artifactId>hibernate</artifactId>
	<version>${hibernate.annotations.version}</version>
      </dependency>
  </dependencies>
...

(2) Pull-up common dependencies to dependencyManagement(parent pom)

If more than one project depends on a specific dependency, you can list the dependency in dependencyManagement. The parent POM can contain a version and a set of exclusions; all the child POM needs to do to reference this dependency is use the groupId and artifactId. Child projects can omit the version and exclusions if the dependency is listed in dependencyManagement.


(3) Use built-in projectversion andgroupId for sibling projects

Use ${project.version}and${project.groupId} when referring to a sibling project. Sibling projects almost always share the samegroupId, and they almost always share the same release version. Using${project.version} will help you avoid the sibling version mismatch problem discussed previously.

如果是兄弟依赖,这样的情况要通过${project.version},${project.groupId}引用父类的的相关信息


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值