如圖所示,項(xiàng)目中定義了這樣幾個(gè)模塊:
- pdd-workflow-build :定義項(xiàng)目版本,及全局配置
- pdd-workflow-dependencies :外部依賴管理,統(tǒng)一管理所有用到的外部依賴的版本
- pdd-workflow-service :項(xiàng)目service模塊
- pdd-workflow-web :項(xiàng)目web模塊
- pdd-parent :聚合模塊
模塊之間的繼承依賴關(guān)系如下圖所示:
網(wǎng)上都說用${revision}這樣的占位符,而且必須叫“revision”這個(gè)名字。但是,我自己實(shí)踐過后發(fā)現(xiàn),這個(gè)變量叫什么都可以(比如:common.version),關(guān)鍵在于要有一個(gè)聚合模塊將所有引用了${revision}的模塊都聚合進(jìn)來,不然打包的時(shí)候還是會找不到版本。
<?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>pdd-workflow-build</artifactId>
<version>${revision}</version>
<relativePath>./pdd-workflow-build/pom.xml</relativePath>
</parent>
<artifactId>pdd-workflow-parent</artifactId>
<packaging>pom</packaging>
<modules>
<module>pdd-workflow-build</module>
<module>pdd-workflow-dependencies</module>
<module>pdd-workflow-service</module>
<module>pdd-workflow-web</module>
</modules>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.example</groupId>
<artifactId>pdd-workflow-dependencies</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>
眾所周知,<parent>中的版本必須是常量,不能是變量,不然就找不到版本。但是,只要我們增加一個(gè)聚合模塊就可以解決這個(gè)問題,在聚合模塊中引用變量是可以的。所以,叫不叫revision根本無所謂,變量名而已,關(guān)鍵在于<modules>。
<?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>pdd-workflow-build</artifactId>
<version>${revision}</version>
<relativePath>../pdd-workflow-build/pom.xml</relativePath>
</parent>
<artifactId>pdd-workflow-dependencies</artifactId>
<packaging>pom</packaging>
<properties>
<dubbo.version>3.2.5</dubbo.version>
<spring-boot.version>3.2.0</spring-boot.version>
<druid.version>1.2.20</druid.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo</artifactId>
<version>${dubbo.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>${druid.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
<?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>pdd-workflow-parent</artifactId>
<version>${revision}</version>
</parent>
<artifactId>pdd-workflow-web</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.example</groupId>
<artifactId>pdd-workflow-service</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
參考Seata,看看Seata是如何統(tǒng)一管理版本的
代碼地址:https://gitee.com/chengjiansheng/pdd-workflow文章來源:http://www.zghlxwxcb.cn/news/detail-748939.html
?文章來源地址http://www.zghlxwxcb.cn/news/detail-748939.html
到了這里,關(guān)于Maven多模塊項(xiàng)目版本統(tǒng)一管理的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!