Idea建立多模塊maven聚合項目

1.怎麼理解maven的繼承和聚合
maven多模塊項目一般由一個父模塊和若干個子模塊構成,每一個模塊都對應着一個pom.xml。它們之間經過繼承和聚合(也稱做多模塊)相互關聯。多模塊適用於一些比較大的項目,經過合理的模塊拆分,實現代碼的複用,便於維護和管理。
繼承:和java中的繼承有點相似,就是父pom.xml聲明的版本和引用的jar,子模塊能夠不用再引用直接調用。
聚合:父模塊包含多個子模塊就是聚合,多個子模塊之間能夠調用,可是要注意關係,不要兩個互相依賴,這樣作的好處就是能夠經過一條命令進行構建java

注意:
groupId是項目組織惟一的標識符,實際對應JAVA的包的結構,artifactId是項目的惟一的標識符,實際對應項目的名稱,就是項目根目錄的名稱。groupId通常分爲多個段,通常第一段爲域,第二段爲公司名稱,第三段一般爲項目名稱。git

2.Idea建立多模塊項目github

  • 2.1建立父模塊(空的maven項目)

    image.png
    image.png
    image.png
    image.png

pom.xml配置
<modelVersion>4.0.0</modelVersion>  
<parent>  
 <groupId>org.springframework.boot</groupId>  
 <artifactId>spring-boot-starter-parent</artifactId>  
 <version>2.1.6.RELEASE</version>  
</parent>  
  
<groupId>cn.yskcoder.fire</groupId>  
<artifactId>fire</artifactId>  
<packaging>pom</packaging>  
<version>v1.0</version>  
  
  
<modules>  
 <module>fire-common</module>  
 <module>fire-dao</module>  
 <module>fire-service</module>  
 <module>fire-web</module>  
</modules>  
  
<properties>  
 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  
 <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>  
 <java.version>1.8</java.version>  
 <spring-boot.version>2.1.6.RELEASE</spring-boot.version>  
  
</properties>
  • 2.2.建立工具類(common)模塊(dao、service同這個操做同樣)

    image.png
    image.png
    image.png

pom.xml配置
<modelVersion>4.0.0</modelVersion>  
<parent>  
 <artifactId>fire</artifactId>  
 <groupId>cn.yskcoder.fire</groupId>  
 <version>v1.0</version>  
</parent>  
  
<!--模塊信息-->  
<packaging>jar</packaging>  
<name>fire-common</name>  
<artifactId>fire-common</artifactId>  
<description>fire 通用工具類模塊</description>  
  
<!--模塊依賴-->  
<dependencies>  
  
</dependencies>
  • 2.3.建立數據庫訪問(dao)模塊(只貼pom.xml代碼)
<modelVersion>4.0.0</modelVersion>  
<parent>  
 <artifactId>fire</artifactId>  
 <groupId>cn.yskcoder.fire</groupId>  
 <version>v1.0</version>  
</parent>  
  
<!--模塊信息-->  
<packaging>war</packaging>  
<name>fire-web</name>  
<artifactId>fire-web</artifactId>  
<description>fire web模塊</description>  
  
<!--模塊依賴-->  
<dependencies>  
 <dependency> <groupId>cn.yskcoder.fire</groupId>  
 <artifactId>fire-service</artifactId>  
 <version>v1.0</version>  
 </dependency>  
 <dependency> <groupId>org.springframework.boot</groupId>  
 <artifactId>spring-boot-starter-web</artifactId>  
 </dependency>  
 <dependency> <groupId>org.springframework.boot</groupId>  
 <artifactId>spring-boot-starter-aop</artifactId>  
 </dependency>  
 <dependency> <groupId>org.springframework.boot</groupId>  
 <artifactId>spring-boot-starter-test</artifactId>  
 <scope>test</scope>  
 </dependency>  
</dependencies>


<build>  
 <plugins>  
     <plugin> 
         <groupId>org.apache.maven.plugins</groupId>  
         <artifactId>maven-compiler-plugin</artifactId>  
         <version>3.1</version>  
         <configuration> 
             <source>${java.version}</source>  
             <target>${java.version}</target>  
         </configuration> 
     </plugin>
 </plugins>
  <resources>  
     <resource> 
        <directory>src/main/webapp</directory>  
        <filtering>false</filtering>  
     </resource> 
     <resource> 
         <directory>src/main/resources</directory>  
         <filtering>true</filtering>  
     </resource> 
 </resources>
</build>

3.Idea打包多模塊項目
clean package -Dmaven.test.skip=trueweb

接下來有空會繼續更新這個項目
https://github.com/yskcoder/Firespring

相關文章
相關標籤/搜索