前段時間,閒着沒事將我的電腦上的 IDEA 換成了最新版本,Maven 也更新爲最新版本,可是發現 IDEA 和 Maven 的集成時,關於依賴 jar 包的更新出現了問題,這裏簡單記錄一下出現的問題以及解決的方案~json
Cris 使用的 IDEA 版本以下(當下最新版本)架構
Maven 版本升級成最新的 3.6.0工具
爲了方便問題的展現,這裏 Cris 新建一個平時開發最經常使用的項目架構 首先新建一個父模塊 father測試
而後選中 father 模塊,咱們能夠以 father 模塊做爲父模塊,新建咱們的子模塊,每一個子模塊負責不一樣的業務spa
實際開發中,咱們都是用父模塊作依賴包的管理,以下.net
<groupId>com.cris</groupId>
<artifactId>father</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>son1</module>
<module>son2</module>
</modules>
<properties>
<fastjson.version>1.2.51</fastjson.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>${fastjson.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
複製代碼
父模塊引入了一個 fastjson 的第三方 jar 包,咱們使用 dependencyManagement
標籤爲管理 jar 包,關於 dependencyManagement
和 dependencies
標籤的不一樣,這裏再也不贅述,你們能夠理解爲父模塊 dependency
標籤管理的 jar 包,都會被子模塊引入;
可是若是是 dependencyManagement
標籤管理的 jar 包則在子模塊顯示引入的時候纔會被導入到子模塊中,不理解的同窗能夠 參考3d
子模塊 son1 的 pom.xml 以下code
<parent>
<artifactId>father</artifactId>
<groupId>com.cris</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>son1</artifactId>
複製代碼
當咱們顯示的在子模塊引入 fastjson 包的時候,cdn
<dependencies>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
</dependency>
</dependencies>
複製代碼
(由於版本由 father 模塊控制,子模塊就能夠不用引入 fastjson 的版本號),咱們發現子模塊沒法引入父模塊定義的 jar 包xml
很簡單,打開 IDEA 的 Maven 設置
在 son2 子模塊的 pom.xml 中一樣引入 fastjson 的依賴
<dependencies>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
</dependency>
</dependencies>
複製代碼
能夠發現,如今 son1 和 son2 子模塊引入來自 father 的 jar 包都成功了
version
標籤
若是想爲全部的子模塊更換 fastjson 的版本號,只須要在 father 模塊中更改便可
<properties>
<fastjson.version>1.2.47</fastjson.version>
</properties>
複製代碼
咱們再看看 son1 模塊的依賴
例如:修改 son2 模塊的依賴
<dependencies>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.51</version>
</dependency>
</dependencies>
複製代碼
即使 father 模塊 fastjson 的版本是 1.2.47,son2 模塊由於顯示的指定優先級更高