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

2. 編譯插件
運行時編譯生成target文件的不會生成JAR包
annotationProcessorPaths是在編譯期間動態(tài)處理事情,例如lombok編譯期間動態(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ì)介紹見文末擴展知識。)

3. 過濾靜態(tài)資源(前后端分離)
表示先開啟過濾,排除掉所有的靜態(tài)文件,以免影響到代碼其他的地方,只保留下面3個用到的
<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>
<!-- 啟用過濾 即該資源中的變量將會被過濾器中的值替換 -->
<filtering>true</filtering>
</resource>
</resources>4. 版本管理
<!-- 統(tǒng)一版本號管理 -->
<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.無法識別${revision}導(dǎo)致版本號沒變 使用flatten之后便會生成一個新的替換占位符的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


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

解決方案
https://github.com/spring-projects/spring-boot/issues/38541#issuecomment-1827462871
//增加maven參數(shù)
<compilerArgs>
<arg>-parameters</arg>
</compilerArgs>
修改完后記得刷新maven依賴clean一下,在重啟項目!!!!!!!!
到此這篇關(guān)于maven多模塊pom配置詳解的文章就介紹到這了,更多相關(guān)maven多模塊內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
使用mybatis報Invalid bound statement解決分析
這篇文章主要為大家介紹了使用mybatis報Invalid bound statement原因解決分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-12-12
spring data jpa @Query注解中delete語句報錯的解決
這篇文章主要介紹了spring data jpa @Query注解中delete語句報錯的解決,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-12-12
SpringBoot開發(fā)案例之打造私有云網(wǎng)盤的實現(xiàn)
這篇文章主要介紹了SpringBoot開發(fā)案例之打造私有云網(wǎng)盤的實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-04-04

