maven多模块工程的优化原则

  1. 1、将各个工程中用到的重复jar包提取到parent的pom.xml中,通过properties属性标注版本信息,子模块只记录jar包,而不记录版本号  
  2.     父模块定义如下:  
  3.     <properties>  
  4.       
  5.         <hibernate.annotations.version>3.3.0.gahibernate.annotations.version>  
  6.       
  7.         <hsqldb.version>1.8.0.7hsqldb.version>  
  8.     
  9.     properties>  
  10.     <dependencyManagement>  
  11.         <dependencies>  
  12.             <dependency>  
  13.                 <groupId>org.hibernategroupId>  
  14.                 <artifactId>hibernate-annotationsartifactId>  
  15.                 <version>${hibernate.annotations.version}version>  
  16.             dependency>  
  17.             <dependency>  
  18.                 <groupId>org.hibernategroupId>  
  19.                 <artifactId>hibernate-commons-annotationsartifactId>  
  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-modelartifactId>  
  29.             <version>${project.version}version>  
  30.         dependency>  
  31.         <dependency>  
  32.             <groupId>org.hibernategroupId>  
  33.             <artifactId>hibernateartifactId>  
  34.         dependency>  
  35.         <dependency>  
  36.             <groupId>org.hibernategroupId>  
  37.             <artifactId>hibernate-annotationsartifactId>  
  38.         dependency>  
  39.         <dependency>  
  40.             <groupId>org.hibernategroupId>  
  41.             <artifactId>hibernate-commons-annotationsartifactId>  
  42.         dependency>  
  43.         <dependency>  
  44.             <groupId>org.apache.geronimo.specsgroupId>  
  45.             <artifactId>geronimo-jta_1.1_specartifactId>  
  46.             <version>1.1version>  
  47.         dependency>  
  48.         <dependency>  
  49.             <groupId>org.springframeworkgroupId>  
  50.             <artifactId>springartifactId>  
  51.         dependency>  
  52.     dependencies>  
  53. 2、子模块都应用父模块的grouId和version,  
  54.   
  55.     <parent>  
  56.         <groupId>org.sonatype.mavenbookgroupId>  
  57.         <artifactId>simple-parentartifactId>  
  58.         <version>1.0version>  
  59.           
  60.         <relativePath>../simple-parent/pom.xmlrelativePath>  
  61.     parent>  
  62.   
  63.     <artifactId>simple-persistartifactId>  
  64.     <packaging>jarpackaging>  
  65.   
  66.     同时,该模块依赖其他模块时采用如下方式配置:  
  67.     <dependency>  
  68.         <groupId>${project.groupId}groupId>  
  69.         <artifactId>simple-modelartifactId>  
  70.         <version>${project.version}version>  
  71.     dependency>  
  72. 3、采用mvn dependency:analyze将每个工程中的间接依赖添加到每个模块的工程中。 

你可能感兴趣的:(maven多模块工程的优化原则)