欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

springboot結(jié)合maven實現(xiàn)多模塊打包

 更新時間:2023年04月21日 08:32:29   作者:IT人的天地  
本文主要介紹了springboot借助maven完成多模塊打包,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧

我們平時在開發(fā)系統(tǒng)時,一般我們的系統(tǒng)工程會被分為多個模塊,一個原因是方便協(xié)同開發(fā),系統(tǒng)間解耦,另外一個很重要的原因是:別的系統(tǒng)需要依賴我們系統(tǒng)的部分功能,我們可能將這部分功能劃分到一個模塊里面,單獨打包提供給對方?,F(xiàn)在我將通過一個示例工程來演示如何借助maven完成springboot應(yīng)用的多模塊打包的操作。

要點:

1、工程存在多個模塊,模塊間有依賴關(guān)系

2、父工程維護工程的主版本號,子模塊直接引用父工程定義的版本號的變量

3、借助flatten-maven-plugin插件完成子模塊pom文件中引用的父工程變量的替換工作

1、 工程結(jié)構(gòu)

test工程結(jié)構(gòu)

test
--test-api
  --src
 ?  --main
  --pom.xml
--test-core
  --src
 ?  --main
 ? ?  --java
 ? ?  --resouce
 ?  --test
--pom.xml

其中test-api模塊為共用模塊,test-core模塊依賴test-api模塊。后續(xù)也會有其他系統(tǒng)依賴test-api模塊,因此需要將test-api模塊發(fā)布到maven私服。

2、工程模塊pom文件配置

2.1、父模塊pom配置

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
 ? ? ? ? xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 ? ? ? ? xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
?
 ?  <parent>
 ? ? ?  <groupId>org.springframework.boot</groupId>
 ? ? ?  <artifactId>spring-boot-starter-parent</artifactId>
 ? ? ?  <version>2.2.6.RELEASE</version>
 ? ? ?  <relativePath/> <!-- lookup parent from repository -->
 ?  </parent>
?
 ?  <modelVersion>4.0.0</modelVersion>
?
 ?  <groupId>org.example</groupId>
 ?  <artifactId>test</artifactId>
 ?  <version>${revision}</version>
 ?  <packaging>pom</packaging>
 ?  <modules>
 ? ? ?  <module>test-api</module>
 ? ? ?  <module>test-core</module>
 ?  </modules>
?
 ?  <properties>
 ? ? ?  <maven.compiler.source>8</maven.compiler.source>
 ? ? ?  <maven.compiler.target>8</maven.compiler.target>
 ? ? ?  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 ? ? ?  <revision>1.0.0</revision>
 ?  </properties>
 ? <!--發(fā)布到遠程倉庫的配置-->
 ?  <distributionManagement>
 ? ? ?  <repository>
 ? ? ? ? ?  <id>releases</id>
 ? ? ? ? ?  <name>releases</name>
 ? ? ? ? ?  <url>http://192.168.1.1/repository/releases/</url>
 ? ? ?  </repository>
?
 ? ? ?  <snapshotRepository>
 ? ? ? ? ?  <id>snapshots</id>
 ? ? ? ? ?  <url>http://192.168.1.1/repository/snapshots/</url>
 ? ? ?  </snapshotRepository>
?
 ?  </distributionManagement>
?
 ?  <build>
 ? ? ?  <plugins>
 ? ? ? ? ?  <plugin>
 ? ? ? ? ? ? ?  <groupId>org.codehaus.mojo</groupId>
 ? ? ? ? ? ? ?  <artifactId>flatten-maven-plugin</artifactId>
 ? ? ? ? ? ? ?  <version>1.4.1</version>
 ? ? ? ? ? ? ?  <configuration>
 ? ? ? ? ? ? ?  </configuration>
 ? ? ? ? ? ? ?  <executions>
 ? ? ? ? ? ? ? ? ?  <!-- enable flattening -->
 ? ? ? ? ? ? ? ? ?  <execution>
 ? ? ? ? ? ? ? ? ? ? ?  <id>flatten</id>
 ? ? ? ? ? ? ? ? ? ? ?  <phase>process-resources</phase>
 ? ? ? ? ? ? ? ? ? ? ?  <goals>
 ? ? ? ? ? ? ? ? ? ? ? ? ?  <goal>flatten</goal>
 ? ? ? ? ? ? ? ? ? ? ?  </goals>
 ? ? ? ? ? ? ? ? ?  </execution>
 ? ? ? ? ? ? ? ? ?  <!-- ensure proper cleanup -->
 ? ? ? ? ? ? ? ? ?  <execution>
 ? ? ? ? ? ? ? ? ? ? ?  <id>flatten.clean</id>
 ? ? ? ? ? ? ? ? ? ? ?  <phase>clean</phase>
 ? ? ? ? ? ? ? ? ? ? ?  <goals>
 ? ? ? ? ? ? ? ? ? ? ? ? ?  <goal>clean</goal>
 ? ? ? ? ? ? ? ? ? ? ?  </goals>
 ? ? ? ? ? ? ? ? ?  </execution>
 ? ? ? ? ? ? ?  </executions>
 ? ? ? ? ?  </plugin>
 ? ? ?  </plugins>
 ?  </build>
?
?
</project>

父模塊很重要的一個配置就是flatten-maven-plugin這個插件,用于打包時替換子模塊中pom文件的引用的父工程的變量,比如revision變量。如果不添加此插件,雖然打包時不會報錯,但是別的系統(tǒng)引用test-api.jar的時候,會出現(xiàn)類似Could not find artifact org.example:test:pom:${revision} in nexus-aliyun 的錯誤,主要原因就是子模塊中引用的父工程的變量未被替換導致的

2.2、test-api模塊配置

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.example</groupId>
        <artifactId>test</artifactId>
        <version>${revision}</version>
        <relativePath>../pom.xml</relativePath>
    </parent>
?
    <artifactId>test-api</artifactId>
?
    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
?
    <dependencies>
?
    </dependencies>
?
</project>

test-api模塊的pom文件指定父工程時,version參數(shù)用變量表示,方便對版本號的維護。后續(xù)升級系統(tǒng)的版本號,只需要修改父工程中的revision變量即可。打包時,子模塊pom文件中的revision會被替換成revision的真實值,此處打包后jar包里的pom文件的{revision}會被替換成revision的真實值,此處打包后jar包里的pom文件的revision會被替換成revision的真實值,此處打包后jar包里的pom文件的{revision}會被替換成1.0.0

2.3、test-core模塊配置

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.example</groupId>
        <artifactId>test</artifactId>
        <version>${revision}</version>
        <relativePath>../pom.xml</relativePath>
    </parent>
?
    <artifactId>test-core</artifactId>
?
    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <!--跳過部署,執(zhí)行deploy時不將本模塊部署到倉庫-->
        <maven.deploy.skip>true</maven.deploy.skip>
    </properties>
?
    <dependencies>
        <dependency>
            <groupId>org.example</groupId>
            <artifactId>test-api</artifactId>
            <version>${revision}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>
?
</project>

test-core模塊直接依賴test-api模塊,通過revison參數(shù)動態(tài)引用父工程中指定的版本號。將test−core打包后,test−core.jar包中的pom文件中的{revison}參數(shù)動態(tài)引用父工程中指定的版本號。將test-core打包后,test-core.jar包中的pom文件中的revison參數(shù)動態(tài)引用父工程中指定的版本號。將test−core打包后,test−core.jar包中的pom文件中的{revision}會被替換成revision參數(shù)的實際值1.0.0

3、工程打包

3.1、執(zhí)行打包

(1)進入test工程根目錄,比如我所在工程根目錄路徑是D:\ideaProject\test,

若執(zhí)行下述命令,

mvn clean install

test-api模塊和test-core模塊都會被打包進本地倉庫。

(2)如果執(zhí)行下述命令,test-api模塊會被部署到遠程倉庫,而test-core模塊則不會被部署到遠程倉庫。

mvn clean deploy

(3)如果只想打包test-api模塊到本地倉庫,或者只想把test-api模塊部署到遠程倉庫,可以進入test-api模塊的主目錄,比如D:\ideaProject\test\test-api,執(zhí)行下述命令

#只安裝到本地倉庫

mvn clean install

#部署到遠程倉庫(該命令會先把包安裝到本地倉庫)

mvn clean deploy

3.2、打包效果

已test-api為例,打包后的test-api-1.00.jar文件中的pom.xml文件內(nèi)容如下所示

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.example</groupId>
  <artifactId>test-api</artifactId>
  <version>1.0.0</version>
  <licenses>
    <license>
      <name>Apache License, Version 2.0</name>
      <url>https://www.apache.org/licenses/LICENSE-2.0</url>
    </license>
  </licenses>
</project>

可以發(fā)現(xiàn),里面引入的父工程的變量已經(jīng)被成功替換。

參考

1、flatten-maven-plugin官網(wǎng)

到此這篇關(guān)于springboot結(jié)合maven實現(xiàn)多模塊打包的文章就介紹到這了,更多相關(guān)springboot maven多模塊打包內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • swagger中如何給請求添加header

    swagger中如何給請求添加header

    這篇文章主要介紹了swagger中如何給請求添加header,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-06-06
  • 迪米特法則_動力節(jié)點Java學院整理

    迪米特法則_動力節(jié)點Java學院整理

    這篇文章主要介紹了迪米特法則,迪米特法則就是一個在類創(chuàng)建方法和屬性時需要遵守的法則,有興趣的可以了解一下
    2017-08-08
  • java進階之了解SpringBoot的配置原理

    java進階之了解SpringBoot的配置原理

    今天帶大家了解SpringBoot的相關(guān)知識,文中對SpringBoot的配置原理作了非常詳細的圖文示例及介紹,需要的朋友可以參考下
    2021-06-06
  • IDEA全局查找關(guān)鍵字的用法解讀

    IDEA全局查找關(guān)鍵字的用法解讀

    這篇文章主要介紹了IDEA全局查找關(guān)鍵字的用法解讀,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-02-02
  • 詳解spring中aop不生效的幾種解決辦法

    詳解spring中aop不生效的幾種解決辦法

    這篇文章主要介紹了詳解spring中aop不生效的幾種解決辦法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-06-06
  • 使用Aop的方式實現(xiàn)自動日志記錄的方式詳細介紹

    使用Aop的方式實現(xiàn)自動日志記錄的方式詳細介紹

    這篇文章主要介紹了使用Aop的方式實現(xiàn)自動日志記錄,通過監(jiān)聽器去監(jiān)聽,當訪問到具體的類方法,通過aop切面去獲取訪問的方法,然后將日志記錄下來,就這種方式給大家介紹的非常詳細,需要的朋友可以參考下
    2022-04-04
  • MyBatis執(zhí)行SQL的兩種方式小結(jié)

    MyBatis執(zhí)行SQL的兩種方式小結(jié)

    本文主要介紹了MyBatis執(zhí)行SQL的兩種方式小結(jié),主要包括SqlSession 發(fā)送SQL和SqlSession獲取Mapper接口,通過Mapper接口發(fā)送SQL,具有一定的參考價值,感興趣的可以了解一下
    2023-10-10
  • Spring循環(huán)依賴的解決辦法,你真的懂了嗎

    Spring循環(huán)依賴的解決辦法,你真的懂了嗎

    循壞依賴即循環(huán)引用,兩個或多個bean相互引用,最終形成一個環(huán)。這篇文章主要介紹了Spring循環(huán)依賴的解決辦法,需要的朋友可以參考下
    2020-06-06
  • SpringSecurity中PasswordEncoder的使用

    SpringSecurity中PasswordEncoder的使用

    密碼存儲和加密是非常重要的,本文主要介紹了SpringSecurity中PasswordEncoder的使用,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2025-01-01
  • java agent使用全解析

    java agent使用全解析

    這篇文章主要介紹了javaagent的相關(guān)資料,文中示例代碼非常詳細,供大家參考和學習,感興趣的朋友可以了解下
    2020-07-07

最新評論