maven多模块pom配置实例详解
作者:酒醉的胡铁
这篇文章主要介绍了maven多模块pom配置实例代码,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧
maven多模块pom配置详解
最外层pom
1.type:pom
相当于引入其他JAR包里的POM文件,里面规定的版本号也可以直接使用**

2. 编译插件
运行时编译生成target文件的不会生成JAR包
annotationProcessorPaths是在编译期间动态处理事情,例如lombok编译期间动态生成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参数,开启此参数可以将编译后的class文件保留原码中的参数名
还可以解决:Name for argument of type [java.lang.String] not specified 问题(详细介绍见文末扩展知识。)

3. 过滤静态资源(前后端分离)
表示先开启过滤,排除掉所有的静态文件,以免影响到代码其他的地方,只保留下面3个用到的
<resources>
<resource>
<directory>src/main/resources</directory>
<!-- 关闭过滤 -->
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<!-- 引入所有 匹配文件进行过滤 -->
<includes>
<include>application*</include>
<include>bootstrap*</include>
<include>banner*</include>
</includes>
<!-- 启用过滤 即该资源中的变量将会被过滤器中的值替换 -->
<filtering>true</filtering>
</resource>
</resources>4. 版本管理
<!-- 统一版本号管理 -->
<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}导致版本号没变 使用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 后在调用接口的时候总是出现下面的报错信息

解决方案
https://github.com/spring-projects/spring-boot/issues/38541#issuecomment-1827462871
//增加maven参数
<compilerArgs>
<arg>-parameters</arg>
</compilerArgs>
修改完后记得刷新maven依赖clean一下,在重启项目!!!!!!!!
到此这篇关于maven多模块pom配置详解的文章就介绍到这了,更多相关maven多模块内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
