springboot~nexus項(xiàng)目打包要注意的地方示例代碼詳解
一個(gè)使用maven制作框架包時(shí),會有一個(gè)主項(xiàng)目,然后它有多個(gè)子項(xiàng)目框架組成,很少一個(gè)工具包一個(gè)工程,像springboot,springcloud都是這種結(jié)構(gòu),主項(xiàng)目用來管理一些依賴包的版本,這對于框架型項(xiàng)目來說是很必要的,而對于業(yè)務(wù)項(xiàng)目來說,因?yàn)槟壳岸际峭扑]使用微服務(wù)的輕量方式,所以不建議用多項(xiàng)目綁定一個(gè)大項(xiàng)目的方式,而都是一個(gè)服務(wù)一個(gè)項(xiàng)目。
主pom文件
主項(xiàng)目的pom文件用來管理依賴包版本,一般在dependencyManagement節(jié)點(diǎn)去聲明它們的版本號,這樣在子項(xiàng)目里可以不聲明相同包的版本信息了
<dependencyManagement> <dependencies> <!--spring boot 版本--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>${spring-boot-dependencies.version}</version> <type>pom</type> <scope>import</scope> </dependency> <!--阿里巴巴組件--> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-alibaba-dependencies</artifactId> <version>${spring-cloud-alibaba-dependencies.version}</version> <type>pom</type> <scope>import</scope> </dependency> <!--spring cloud 版本--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>${spring-cloud.version}</version> <type>pom</type> <scope>import</scope> </dependency> <!-- Spring Boot Web 依賴 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <version>${spring-boot-dependencies.version}</version> <exclusions> <!-- 排除Tomcat 以使用 Undertow --> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </exclusion> </exclusions> </dependency> <!-- Google 編碼助手 --> <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>${guava.version}</version> </dependency> <!-- Mysql 驅(qū)動 --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>${mysql.drive.version}</version> </dependency> <!-- HikariCP 連接池 --> <dependency> <groupId>com.zaxxer</groupId> <artifactId>HikariCP</artifactId> <version>${HikariCP.version}</version> </dependency> <!-- MyBatis 增強(qiáng)工具 --> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>${mybatis-plus-boot-starter.version}</version> </dependency> <!-- Alibaba json解析器 --> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>${fastjson.version}</version> </dependency> <!-- 接口文檔 --> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>${springfox-swagger2.version}</version> </dependency> <!-- 接口文檔 UI --> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>${springfox-swagger2.version}</version> </dependency> <!-- HTTP 客戶端請求 --> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>${httpclient.version}</version> </dependency> <!-- Feign 客戶端請求 --> <dependency> <groupId>io.github.openfeign</groupId> <artifactId>feign-httpclient</artifactId> <version>${feign-httpclient.version}</version> </dependency> </dependencies> </dependencyManagement>
如果項(xiàng)目希望進(jìn)行發(fā)布到nexus私服上,需要配置distributionManagement節(jié)點(diǎn)的信息,它對應(yīng)你的.m2/settings.xml里的profile節(jié)點(diǎn)信息
<distributionManagement> <repository> <id>releases</id> <name>Nexus Release Repository</name> <url>http://192.168.0.203:8081/repository/maven-releases/</url> </repository> <snapshotRepository> <id>snapshots</id> <name>Nexus Snapshot Repository</name> <url>http://192.168.0.203:8081/repository/maven-snapshots/</url> </snapshotRepository>
使用deploy發(fā)布項(xiàng)目
第一次把工具包發(fā)到nexus時(shí),需要在點(diǎn)擊主項(xiàng)目的 deploy它會把主項(xiàng)目和其子項(xiàng)目同時(shí)發(fā)到nexus上面,后續(xù)可以只deploy修改的項(xiàng)目
在具體項(xiàng)目里使用它
直接在項(xiàng)目的pom里,添加對應(yīng)的工具包即可,工具包的項(xiàng)目依賴你不需要關(guān)心
<dependency> <groupId>com.lind</groupId> <artifactId>lind-common</artifactId> <version>${lind-common.version}</version> </dependency>
注意:對于框架型項(xiàng)目,需要保存你的工具包依賴的項(xiàng)目也在nexus上面,否則會導(dǎo)致加載失敗。
到此這篇關(guān)于springboot~nexus項(xiàng)目打包要注意的地方的文章就介紹到這了,更多相關(guān)springboot nexus項(xiàng)目打包內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
java 使用ConcurrentHashMap和計(jì)數(shù)器實(shí)現(xiàn)鎖
這篇文章主要介紹了java 使用ConcurrentHashMap和計(jì)數(shù)器實(shí)現(xiàn)鎖的相關(guān)資料,需要的朋友可以參考下2017-05-05Java實(shí)現(xiàn)將類數(shù)據(jù)逐行寫入CSV文件的方法詳解
這篇文章主要為大家詳細(xì)介紹了Java如何實(shí)現(xiàn)將類數(shù)據(jù)逐行寫入CSV文件,文中的示例代碼講解詳細(xì),具有一定的參考價(jià)值,需要的可以借鑒一下2022-11-11Java提示解析時(shí)已到達(dá)文件結(jié)尾的解決方法
在本篇文章中小編給大家分享了關(guān)于Java提示解析時(shí)已到達(dá)文件結(jié)尾的解決方法,需要的朋友們學(xué)習(xí)下。2019-07-07Java數(shù)組擴(kuò)容實(shí)現(xiàn)方法解析
這篇文章主要介紹了Java數(shù)組擴(kuò)容實(shí)現(xiàn)方法解析,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-11-11Druid連接池的自定義過濾功能實(shí)現(xiàn)方法
在數(shù)據(jù)密集型應(yīng)用中,監(jiān)控和分析數(shù)據(jù)庫操作對于確保性能和穩(wěn)定性至關(guān)重要,本文將探討如何實(shí)現(xiàn)一個(gè)自定義的Druid過濾器來捕獲數(shù)據(jù)庫請求并進(jìn)行日志記錄,以輔助開發(fā)和維護(hù)工作,需要的朋友可以參考下2023-11-11