maven項(xiàng)目在實(shí)踐中的構(gòu)建管理之路的方法
前言
最近一個(gè)月參與了公司幾個(gè)項(xiàng)目的腳手架構(gòu)建,適當(dāng)總結(jié)下經(jīng)驗(yàn)。之前見(jiàn)過(guò)太多項(xiàng)目依賴,構(gòu)建,管理混亂不堪,導(dǎo)致后續(xù)的維護(hù)性差,甚至出現(xiàn)由此引發(fā)的事故。當(dāng)時(shí)就有一個(gè)規(guī)范管理的想法。
依賴管理
依賴管理,其實(shí)就是依賴范圍的管理。這里我叫他 依賴池。也就是 所有相關(guān)項(xiàng)目的依賴只能從這個(gè)池子里拿,不能超出其范圍。池子里的依賴我們定義為都是久經(jīng)考驗(yàn)的同志。以maven工程為例,我們可以定義 一個(gè)名為ooxx-dependencies 的 pom 類型的工程。這里用來(lái)存放我們經(jīng)過(guò)技術(shù)選型并測(cè)試通過(guò)的依賴。每次依賴變動(dòng)發(fā)布都要有新的版本號(hào)。也就是 依賴池的迭代一定要以版本號(hào)為標(biāo)志,多版本并行。
<?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.ooxx</groupId> <artifactId>ooxx-dependencies</artifactId> <version>1.0.0.RELEASE</version> <name>ooxx dependencies</name> <description>the root dependencies</description> <properties> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> <springboot.version>2.1.5.RELEASE</springboot.version> <spring-boot-admin.version>2.1.4</spring-boot-admin.version> <springSecurityJwt.version>1.0.10.RELEASE</springSecurityJwt.version> <mysql.version>5.1.47</mysql.version> <hikari.version>3.2.0</hikari.version> <hutool.version>4.5.5</hutool.version> <mybatisplus.version>3.1.1</mybatisplus.version> <wexin-pay.version>3.2.0</wexin-pay.version> <wexin-miniapp.version>3.2.0</wexin-miniapp.version> <swagger.version>2.9.2</swagger.version> </properties> <distributionManagement> <repository> <id>nexus</id> <name>Releases</name> <url>http://url/repository/maven-releases</url> </repository> <snapshotRepository> <id>nexus</id> <name>Snapshot</name> <url>http://url/repository/maven-snapshots</url> </snapshotRepository> </distributionManagement> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>${springboot.version}</version> <type>pom</type> <scope>import</scope> </dependency> <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-dependencies</artifactId> <version>${spring-boot-admin.version}</version> <type>pom</type> <scope>import</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <version>${springboot.version}</version> <!-- 排除Tomcat依賴 --> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-jwt</artifactId> <version>${springSecurityJwt.version}</version> </dependency> <dependency> <groupId>com.zaxxer</groupId> <artifactId>HikariCP</artifactId> <version>${hikari.version}</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>${mysql.version}</version> </dependency> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>${mybatisplus.version}</version> </dependency> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-generator</artifactId> <version>${mybatisplus.version}</version> </dependency> <!--swagger2--> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>${swagger.version}</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>${swagger.version}</version> </dependency> </dependencies> </dependencyManagement> </project>
然后,我們根據(jù)業(yè)務(wù)會(huì)定義一個(gè)parent項(xiàng)目,這個(gè)項(xiàng)目同樣是pom工程,區(qū)別于依賴池的是, 依賴池基于技術(shù)棧而不關(guān)注業(yè)務(wù),parent關(guān)注于業(yè)務(wù),不同業(yè)務(wù)application 依賴不同的parent,parent 來(lái)定義具體業(yè)務(wù)的module層次劃分。當(dāng)然parent 必須從依賴池構(gòu)建??赡芾痈庇^, 我們有一個(gè)項(xiàng)目,模塊分為:1.后臺(tái)管理模塊 2.app接口模塊 3.通用依賴模塊 4.數(shù)據(jù)層模塊 5.app 啟動(dòng)模塊 可以結(jié)合上面例子進(jìn)行如下構(gòu)建parent
<?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.ooxx</groupId> <artifactId>ooxx-parent</artifactId> <version>1.0.0</version> <packaging>pom</packaging> <name>parent</name> <description>the parent</description> <properties> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> <ooxx.version>1.0.0</ooxx.version> <ooxx-dependencies.version>1.0.0.RELEASE</ooxx-dependencies.version> </properties> <dependencyManagement> <dependencies> <!--依賴池 --> <dependency> <groupId>com.ooxx</groupId> <artifactId>ooxx-dependencies</artifactId> <version>${ooxx-dependencies.version}</version> <type>pom</type> <scope>import</scope> </dependency> <!--數(shù)據(jù)層模塊 --> <dependency> <groupId>com.ooxx</groupId> <artifactId>ooxx-db</artifactId> <version>${ooxx.version}</version> </dependency> <!--通用依賴模塊 --> <dependency> <groupId>com.ooxx</groupId> <artifactId>ooxx-common</artifactId> <version>${ooxx.version}</version> </dependency> <!-- 后臺(tái)管理模塊--> <dependency> <groupId>com.ooxx</groupId> <artifactId>ooxx-manage-api</artifactId> <version>${ooxx.version}</version> </dependency> <!--app接口模塊 --> <dependency> <groupId>com.ooxx</groupId> <artifactId>ooxx-app-api</artifactId> <version>${ooxx.version}</version> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>cn.hutool</groupId> <artifactId>hutool-all</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <scope>compile</scope> </dependency> </dependencies> </project>
上述的具體如 app接口模塊 可以直接引用依賴池中的依賴進(jìn)行具體開(kāi)發(fā)。
補(bǔ)充
同時(shí)建議 版本號(hào) 為{數(shù)字}.{說(shuō)明格式}。比如1.0.0.RC、 1.0.0.GA 等用于不同的場(chǎng)景。pom 名稱盡量 模板化 如 ooxx-parent 下的子module 命名為 ooxx-db、ooxx-app-api 之類。這樣可以用maven 模板生成統(tǒng)一的模板項(xiàng)目以快速構(gòu)建項(xiàng)目。同時(shí)達(dá)到 “見(jiàn)其名而知其意”的效果。因個(gè)人能力有限,不足之處或者更好的建議還望多多指教。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
為什么mybatis中的SqlSession一定要關(guān)閉
這篇文章主要介紹了為什么mybatis中的SqlSession一定要關(guān)閉,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-12-12SpringBoot如何使用feign實(shí)現(xiàn)遠(yuǎn)程接口調(diào)用和錯(cuò)誤熔斷
這篇文章主要介紹了SpringBoot如何使用feign實(shí)現(xiàn)遠(yuǎn)程接口調(diào)用和錯(cuò)誤熔斷,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-12-12Springboot的spring-boot-maven-plugin導(dǎo)入失敗的解決方案
這篇文章主要介紹了Springboot的spring-boot-maven-plugin導(dǎo)入失敗的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-07-07JAVA位運(yùn)算的知識(shí)點(diǎn)總結(jié)
在本篇文章里小編給大家整理的是關(guān)于JAVA有關(guān)位運(yùn)算的全套梳理,需要的朋友們可以參考學(xué)習(xí)下。2020-03-03Java Excel文件加密保護(hù)數(shù)據(jù)安全
這篇文章主要為大家介紹了Java Excel文件加密保護(hù)數(shù)據(jù)安全的方法詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-10-10