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

Maven項目繼承實現(xiàn)過程圖解

 更新時間:2020年08月05日 11:57:43   作者:護花使者  
這篇文章主要介紹了Maven項目繼承實現(xiàn)過程圖解,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下

多個maven項目之間難免有重復(fù)的pom配置,重復(fù)的配置沒必要重復(fù)寫,maven提供了父子繼承的關(guān)系,重復(fù)的依賴直接放在父項目的pom中。

所以不希望每個開發(fā)者隨意定義maven版本依賴,可以在父項目中進行說明,然后子項目沿用即可。

idea創(chuàng)建父項目(這是一個父項目,也是一個空項目,只需要pom.xml,編寫相關(guān)的依賴, 父項目必須用pom打包的方式):

編輯父項目pom.xml

<?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>

  <groupId>com.linewell</groupId>
  <artifactId>maven-parent</artifactId>
  <version>1.0-SNAPSHOT</version>
  <!--父項目必須是pom-->
  <packaging>pom</packaging>

  <!--定義參數(shù)-->
  <properties>
    <common.version>2.6</common.version>
    <spring.version>4.3.6.RELEASE</spring.version>
  </properties>

  <!--這邊的依賴子項目會繼承-->
  <dependencies>
    <dependency>
      <groupId>commons-io</groupId>
      <artifactId>commons-io</artifactId>
      <version>${common.version}</version>
    </dependency>
  </dependencies>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>spring-context-support</groupId>
        <artifactId>org.springframework</artifactId>
        <version>${spring.version}</version>
      </dependency>
    </dependencies>
  </dependencyManagement>
  
</project>

這邊需要說明下,dependencyManagement,這邊的依賴不會被繼承,如果子項目導(dǎo)入了這個依賴,可以不用寫版本號,會以父項目的為主,因為有的子項目不一定會用父項目中的所有依賴。個別子項目依賴到的包可以放在這里,然后不需要寫版本號,會自動引用父項目。

創(chuàng)建一個子項目,編輯子項目的pom.xml如下:

<?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>

  <groupId>com.linewell</groupId>
  <artifactId>maven-children</artifactId>
  <version>1.0-SNAPSHOT</version>

  <parent>
    <groupId>com.linewell</groupId>
    <artifactId>maven-parent</artifactId>
    <version>1.0-SNAPSHOT</version>
    <relativePath>../mavenparent/pom.xml</relativePath>
  </parent>

</project>

可以看到commons-io進來了,spring-context-support沒進來。

我現(xiàn)在不添加spring-context-support的版本,然后看下結(jié)果,是會以父項目的版本為主。可以看到如下引入的也是父項目中的4.3.6

<?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>com.linewell</groupId>
    <artifactId>maven-parent</artifactId>
    <version>1.0-SNAPSHOT</version>
    <relativePath>../mavenparent/pom.xml</relativePath>
  </parent>

  <groupId>com.linewell</groupId>
  <artifactId>maven-children</artifactId>
  <version>1.0-SNAPSHOT</version>

  <dependencies>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context-support</artifactId>
    </dependency>
  </dependencies>
</project>

那么問題來了,如果子項目指定了版本會怎么樣?

編輯子項目pom.xml, 如下可以發(fā)現(xiàn),如果子項目有明確指定依賴以及具體版本,與父項目發(fā)生沖突會以子項目的依賴為準。

<?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>com.linewell</groupId>
    <artifactId>maven-parent</artifactId>
    <version>1.0-SNAPSHOT</version>
    <relativePath>../mavenparent/pom.xml</relativePath>
  </parent>

  <groupId>com.linewell</groupId>
  <artifactId>maven-children</artifactId>
  <version>1.0-SNAPSHOT</version>

  <dependencies>
    <dependency>
      <groupId>commons-io</groupId>
      <artifactId>commons-io</artifactId>
      <version>2.5</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context-support</artifactId>
      <version>5.2.5.RELEASE</version>
    </dependency>
  </dependencies>

</project>

ps:如果父項目中執(zhí)行了mvn install安裝到了本地倉庫,然后子項目中引入父GAV的時候可以不用寫路徑relativePath屬性。

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 從零開始學(xué)springboot整合feign跨服務(wù)調(diào)用的方法

    從零開始學(xué)springboot整合feign跨服務(wù)調(diào)用的方法

    這篇文章主要介紹了從零開始學(xué)springboot整合feign跨服務(wù)調(diào)用的方法,本文給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-03-03
  • SpringBoot利用redis集成消息隊列的方法

    SpringBoot利用redis集成消息隊列的方法

    這篇文章主要介紹了SpringBoot利用redis集成消息隊列的方法,需要的朋友可以參考下
    2017-08-08
  • java使用xpath和dom4j解析xml

    java使用xpath和dom4j解析xml

    XPath是一門在XML文檔中查找信息的語言,下面介紹一下java使用xpath和dom4j解析xml的示例,大家參考使用吧
    2014-01-01
  • vscode搭建java開發(fā)環(huán)境的實現(xiàn)步驟

    vscode搭建java開發(fā)環(huán)境的實現(xiàn)步驟

    本文主要介紹了vscode搭建java開發(fā)環(huán)境,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-03-03
  • Spring BeanPostProcessor接口使用詳解

    Spring BeanPostProcessor接口使用詳解

    本篇文章主要介紹了Spring BeanPostProcessor接口使用詳解,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-01-01
  • 深入講解RocketMQ原理

    深入講解RocketMQ原理

    這篇文章主要介紹了詳解SpringBoot整合RocketMQ,RocketMQ作為一款純java、分布式、隊列模型的開源消息中間件,支持事務(wù)消息、順序消息、批量消息、定時消息、消息回溯等,需要的朋友可以參考下
    2023-07-07
  • java 文件大數(shù)據(jù)Excel下載實例代碼

    java 文件大數(shù)據(jù)Excel下載實例代碼

    這篇文章主要介紹了java 文件大數(shù)據(jù)Excel下載實例代碼的相關(guān)資料,需要的朋友可以參考下
    2017-04-04
  • 使用dynamic datasource springboot starter實現(xiàn)多數(shù)據(jù)源及源碼分析

    使用dynamic datasource springboot starter實現(xiàn)多數(shù)據(jù)源及源碼分析

    這篇文章主要介紹了使用dynamic-datasource-spring-boot-starter做多數(shù)據(jù)源及源碼分析,本文給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-09-09
  • java io讀取文件操作代碼實例

    java io讀取文件操作代碼實例

    這篇文章主要介紹了java io讀取文件操作代碼實例,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2019-11-11
  • 淺析Java多線程同步synchronized

    淺析Java多線程同步synchronized

    本篇文章給大家詳細分析了Java多線程同步synchronized的相關(guān)知識點,需要的讀者們可以參考學(xué)習(xí)下。
    2018-02-02

最新評論

宜州市| 新和县| 东平县| 同仁县| 济宁市| 芷江| 分宜县| 娱乐| 讷河市| 萝北县| 辉南县| 永仁县| 乌兰县| 莫力| 嘉兴市| 思南县| 邻水| 平远县| 麻城市| 绵竹市| 绍兴县| 柘城县| 平邑县| 成武县| 蒙山县| 荆门市| 斗六市| 屯门区| 即墨市| 周宁县| 梅河口市| 黎川县| 杨浦区| 虹口区| 延长县| 申扎县| 新龙县| 泸溪县| 鹤岗市| 南阳市| 闻喜县|