最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

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

要點(diǎn):

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

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

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ù)也會(huì)有其他系統(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ā)布到遠(yuǎn)程倉庫的配置-->
 ?  <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>

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

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文件指定父工程時(shí),version參數(shù)用變量表示,方便對(duì)版本號(hào)的維護(hù)。后續(xù)升級(jí)系統(tǒng)的版本號(hào),只需要修改父工程中的revision變量即可。打包時(shí),子模塊pom文件中的revision會(huì)被替換成revision的真實(shí)值,此處打包后jar包里的pom文件的{revision}會(huì)被替換成revision的真實(shí)值,此處打包后jar包里的pom文件的revision會(huì)被替換成revision的真實(shí)值,此處打包后jar包里的pom文件的{revision}會(huì)被替換成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時(shí)不將本模塊部署到倉庫-->
        <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ù)動(dòng)態(tài)引用父工程中指定的版本號(hào)。將test−core打包后,test−core.jar包中的pom文件中的{revison}參數(shù)動(dòng)態(tài)引用父工程中指定的版本號(hào)。將test-core打包后,test-core.jar包中的pom文件中的revison參數(shù)動(dòng)態(tài)引用父工程中指定的版本號(hào)。將test−core打包后,test−core.jar包中的pom文件中的{revision}會(huì)被替換成revision參數(shù)的實(shí)際值1.0.0

3、工程打包

3.1、執(zhí)行打包

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

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

mvn clean install

test-api模塊和test-core模塊都會(huì)被打包進(jìn)本地倉庫。

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

mvn clean deploy

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

#只安裝到本地倉庫

mvn clean install

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

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實(shí)現(xiàn)多模塊打包的文章就介紹到這了,更多相關(guān)springboot maven多模塊打包內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • java實(shí)現(xiàn)郵件發(fā)送詳解

    java實(shí)現(xiàn)郵件發(fā)送詳解

    這篇文章主要為大家詳細(xì)介紹了java實(shí)現(xiàn)郵件發(fā)送示例,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-03-03
  • Spring的跨域的幾個(gè)方案

    Spring的跨域的幾個(gè)方案

    這篇文章主要介紹了Spring的跨域的幾個(gè)方案,CrossOrigin、addCorsMappings、CorsFIlter等方案,具有一定的參考價(jià)值,需要的小伙伴可以參考一下,希望對(duì)你有所幫助
    2022-02-02
  • springboot之Validation參數(shù)校驗(yàn)詳細(xì)解讀

    springboot之Validation參數(shù)校驗(yàn)詳細(xì)解讀

    這篇文章主要介紹了springboot之Validation參數(shù)校驗(yàn)詳細(xì)解讀,本篇是關(guān)于springboot的參數(shù)校驗(yàn)知識(shí),當(dāng)然也適用其它java應(yīng)用,讀完本篇將學(xué)會(huì)基本的參數(shù)校驗(yàn),自定義參數(shù)校驗(yàn)和分組參數(shù)校驗(yàn),需要的朋友可以參考下
    2023-10-10
  • Java之理解Redis回收算法LRU案例講解

    Java之理解Redis回收算法LRU案例講解

    這篇文章主要介紹了Java之理解Redis回收算法LRU案例講解,本篇文章通過簡(jiǎn)要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下
    2021-08-08
  • 在?Spring?Boot?中使用?Quartz?調(diào)度作業(yè)的示例詳解

    在?Spring?Boot?中使用?Quartz?調(diào)度作業(yè)的示例詳解

    這篇文章主要介紹了在?Spring?Boot?中使用?Quartz?調(diào)度作業(yè)的示例詳解,在本文中,我們將看看如何使用Quartz框架來調(diào)度任務(wù),Quartz支持在特定時(shí)間運(yùn)行作業(yè)、重復(fù)作業(yè)執(zhí)行、將作業(yè)存儲(chǔ)在數(shù)據(jù)庫中以及Spring集成,需要的朋友可以參考下
    2022-07-07
  • java類的定義與使用舉例詳解

    java類的定義與使用舉例詳解

    這篇文章主要給大家介紹了關(guān)于java類的定義與使用的相關(guān)資料,類的方法是用來定義類的行為,在方法中通過操作類的成員變量、編寫業(yè)務(wù)邏輯、返回 結(jié)果等實(shí)現(xiàn)類的業(yè)務(wù)行為,需要的朋友可以參考下
    2023-11-11
  • Mybatis plus邏輯刪除失敗的BUG操作

    Mybatis plus邏輯刪除失敗的BUG操作

    這篇文章主要介紹了Mybatis plus邏輯刪除失敗的BUG操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2020-11-11
  • MyBatis獲取插入記錄的自增長(zhǎng)字段值(ID)

    MyBatis獲取插入記錄的自增長(zhǎng)字段值(ID)

    本文分步驟給大家介紹了MyBatis獲取插入記錄的自增長(zhǎng)字段值的方法,在文中給大家提到了mybatis返回插入數(shù)據(jù)的自增長(zhǎng)id,需要的朋友可以參考下
    2017-11-11
  • Flink實(shí)戰(zhàn)之實(shí)現(xiàn)流式數(shù)據(jù)去重

    Flink實(shí)戰(zhàn)之實(shí)現(xiàn)流式數(shù)據(jù)去重

    流式數(shù)據(jù)是一種源源不斷產(chǎn)生的數(shù)據(jù),本文探索了一種流式大數(shù)據(jù)的實(shí)時(shí)去重方法,不一定適用于所有場(chǎng)景,不過或許可以給面對(duì)相似問題的你一點(diǎn)點(diǎn)啟發(fā),
    2025-03-03
  • 基于JavaMail實(shí)現(xiàn)郵件發(fā)送

    基于JavaMail實(shí)現(xiàn)郵件發(fā)送

    這篇文章主要為大家詳細(xì)介紹了基于JavaMail實(shí)現(xiàn)郵件發(fā)送功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-03-03

最新評(píng)論

比如县| 沙湾县| 定安县| 米林县| 武宣县| 新绛县| 台山市| 旬阳县| 鄂托克前旗| 灵宝市| 天水市| 望城县| 犍为县| 蓝山县| 高要市| 新津县| 韩城市| 平塘县| 雷波县| 丘北县| 青阳县| 武冈市| 晋城| 葫芦岛市| 进贤县| 仙桃市| 盘山县| 那曲县| 陆良县| 宁波市| 旺苍县| 玉环县| 四川省| 贺兰县| 河间市| 咸宁市| 米林县| 保山市| 龙州县| 利津县| 名山县|