maven多模块工程的优化原则

  1. 1、将各个工程中用到的重复jar包提取到parent的pom.xml中,通过properties属性标注版本信息,子模块只记录jar包,而不记录版本号  
  2.     父模块定义如下:  
  3.     <properties>  
  4.       
  5.         <hibernate.annotations.version>3.3.0.ga</hibernate.annotations.version>  
  6.       
  7.         <hsqldb.version>1.8.0.7</hsqldb.version>  
  8.     
  9.     </properties>  
  10.     <dependencyManagement>  
  11.         <dependencies>  
  12.             <dependency>  
  13.                 <groupId>org.hibernate</groupId>  
  14.                 <artifactId>hibernate-annotations</artifactId>  
  15.                 <version>${hibernate.annotations.version}</version>  
  16.             </dependency>  
  17.             <dependency>  
  18.                 <groupId>org.hibernate</groupId>  
  19.                 <artifactId>hibernate-commons-annotations</artifactId>  
  20.                 <version>${hibernate.annotations.version}</version>  
  21.             </dependency>  
  22.         <dependencies>  
  23.     <dependencyManagement>  
  24.     子模块中定义如下:  
  25.     <dependencies>  
  26.         <dependency>  
  27.             <groupId>${project.groupId}</groupId>  
  28.             <artifactId>simple-model</artifactId>  
  29.             <version>${project.version}</version>  
  30.         </dependency>  
  31.         <dependency>  
  32.             <groupId>org.hibernate</groupId>  
  33.             <artifactId>hibernate</artifactId>  
  34.         </dependency>  
  35.         <dependency>  
  36.             <groupId>org.hibernate</groupId>  
  37.             <artifactId>hibernate-annotations</artifactId>  
  38.         </dependency>  
  39.         <dependency>  
  40.             <groupId>org.hibernate</groupId>  
  41.             <artifactId>hibernate-commons-annotations</artifactId>  
  42.         </dependency>  
  43.         <dependency>  
  44.             <groupId>org.apache.geronimo.specs</groupId>  
  45.             <artifactId>geronimo-jta_1.1_spec</artifactId>  
  46.             <version>1.1</version>  
  47.         </dependency>  
  48.         <dependency>  
  49.             <groupId>org.springframework</groupId>  
  50.             <artifactId>spring</artifactId>  
  51.         </dependency>  
  52.     </dependencies>  
  53. 2、子模块都应用父模块的grouId和version,  
  54.   
  55.     <parent>  
  56.         <groupId>org.sonatype.mavenbook</groupId>  
  57.         <artifactId>simple-parent</artifactId>  
  58.         <version>1.0</version>  
  59.         <!-- 如果没有该属性则该工程必须放到simpe-parent下-->  
  60.         <relativePath>../simple-parent/pom.xml</relativePath>  
  61.     </parent>  
  62.   
  63.     <artifactId>simple-persist</artifactId>  
  64.     <packaging>jar</packaging>  
  65.   
  66.     同时,该模块依赖其他模块时采用如下方式配置:  
  67.     <dependency>  
  68.         <groupId>${project.groupId}</groupId>  
  69.         <artifactId>simple-model</artifactId>  
  70.         <version>${project.version}</version>  
  71.     </dependency>  
  72. 3、采用mvn dependency:analyze将每个工程中的间接依赖添加到每个模块的工程中。 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值