maven多模塊pom配置實(shí)例詳解
maven多模塊pom配置詳解
最外層pom
1.type:pom
相當(dāng)于引入其他JAR包里的POM文件,里面規(guī)定的版本號(hào)也可以直接使用**

2. 編譯插件
運(yùn)行時(shí)編譯生成target文件的不會(huì)生成JAR包
annotationProcessorPaths是在編譯期間動(dòng)態(tài)處理事情,例如lombok編譯期間動(dòng)態(tài)生成get、set
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.verison}</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
<annotationProcessorPaths>
<path>
<groupId>com.github.therapi</groupId>
<artifactId>therapi-runtime-javadoc-scribe</artifactId>
<version>${therapi-javadoc.version}</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</path>
<path>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<version>${spring-boot.version}</version>
</path>
<path>
<groupId>io.github.linpeilie</groupId>
<artifactId>mapstruct-plus-processor</artifactId>
<version>${mapstruct-plus.version}</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-mapstruct-binding</artifactId>
<version>${mapstruct-plus.lombok.version}</version>
</path>
</annotationProcessorPaths>
<compilerArgs>
<arg>-parameters</arg>
</compilerArgs>
</configuration>
</plugin>compilerArgs
jdk中新增-parameters參數(shù),開啟此參數(shù)可以將編譯后的class文件保留原碼中的參數(shù)名
還可以解決:Name for argument of type [java.lang.String] not specified 問題(詳細(xì)介紹見文末擴(kuò)展知識(shí)。)

3. 過濾靜態(tài)資源(前后端分離)
表示先開啟過濾,排除掉所有的靜態(tài)文件,以免影響到代碼其他的地方,只保留下面3個(gè)用到的
<resources>
<resource>
<directory>src/main/resources</directory>
<!-- 關(guān)閉過濾 -->
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<!-- 引入所有 匹配文件進(jìn)行過濾 -->
<includes>
<include>application*</include>
<include>bootstrap*</include>
<include>banner*</include>
</includes>
<!-- 啟用過濾 即該資源中的變量將會(huì)被過濾器中的值替換 -->
<filtering>true</filtering>
</resource>
</resources>4. 版本管理
<!-- 統(tǒng)一版本號(hào)管理 -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>${flatten-maven-plugin.version}</version>
<configuration>
<updatePomFile>true</updatePomFile>
<flattenMode>resolveCiFriendliesOnly</flattenMode>
</configuration>
<executions>
<execution>
<id>flatten</id>
<phase>process-resources</phase>
<goals>
<goal>flatten</goal>
</goals>
</execution>
<execution>
<id>flatten.clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>子類pom.無法識(shí)別${revision}導(dǎo)致版本號(hào)沒變 使用flatten之后便會(huì)生成一個(gè)新的替換占位符的pom文件

原文鏈接:maven 版本管理與 flatten-maven-plugin
需要打包的模塊pom
1. 打包插件
jar包和war包都有
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- jar包的-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>${maven-jar-plugin.version}</version>
</plugin>
<!-- war包的-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>${maven-war-plugin.version}</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<warName>${project.artifactId}</warName>
</configuration>
</plugin>
</plugins>
</build>2. 引入自定義的moudle,一起打成JAR


擴(kuò)展:
SpringBoo3 + jdk17 Name for argument of type [java.lang.String] not specified
項(xiàng)目配置:SpringBoot3 + jdk17
問題說明
升級(jí) SpringBoot3 后在調(diào)用接口的時(shí)候總是出現(xiàn)下面的報(bào)錯(cuò)信息

解決方案
https://github.com/spring-projects/spring-boot/issues/38541#issuecomment-1827462871
//增加maven參數(shù)
<compilerArgs>
<arg>-parameters</arg>
</compilerArgs>
修改完后記得刷新maven依賴clean一下,在重啟項(xiàng)目!!!!!!!!
到此這篇關(guān)于maven多模塊pom配置詳解的文章就介紹到這了,更多相關(guān)maven多模塊內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
使用mybatis報(bào)Invalid bound statement解決分析
這篇文章主要為大家介紹了使用mybatis報(bào)Invalid bound statement原因解決分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-12-12
spring data jpa @Query注解中delete語句報(bào)錯(cuò)的解決
這篇文章主要介紹了spring data jpa @Query注解中delete語句報(bào)錯(cuò)的解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-12-12
Java對(duì)象比較之equals與hashCode詳解
這篇文章主要介紹了Java對(duì)象比較之equals與hashCode詳解,equals?方法和?hashCode?方法是?Object?類中的兩個(gè)基礎(chǔ)方法,它們共同協(xié)作來判斷兩個(gè)對(duì)象是否相等,需要的朋友可以參考下2023-12-12
SpringBoot開發(fā)案例之打造私有云網(wǎng)盤的實(shí)現(xiàn)
這篇文章主要介紹了SpringBoot開發(fā)案例之打造私有云網(wǎng)盤的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-04-04
Sentinel自定義異常的三種實(shí)現(xiàn)方式
Spring Cloud Alibaba Sentinel 是目前主流并開源的流量控制和系統(tǒng)保護(hù)組件,Spring Cloud Alibaba Sentinel 有 3 種自定義異常的實(shí)現(xiàn)方式,本文小編將通過代碼示例給大家詳細(xì)的介紹這三種實(shí)現(xiàn)方式,需要的朋友可以參考下2023-11-11

