1.明确好用的
参考链接:
SpringBoot+Maven多模块项目(创建、依赖、打包可执行jar包部署测试)完整流程 - tianlong88 - 博客园
SpringBoot+Maven 多模块项目的构建、运行、打包实战|8月更文挑战 - 掘金
注意事项:
1.idea中project structure
2.父工程用<packaging>pom</packaging>,子模块用<packaging>jar</packaging>
3.在父pom文件里,<dependencyManagement>标签下的依赖,实际上未引用,在子pom文件里需要在<dependencies>标签下自己引入
4.如果其中的子模块需要引入其他子模块,使用如下方式引用
<dependencies> <dependency> <groupId>统一的groupId</groupId> <artifactId>子模块名</artifactId> </dependency> </dependencies>
5.在springboot application 所在的模块下的pom文件里写而不是最外层的pom.xml
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>springboot application main class 入口</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal><!--可以把依赖的包都打包到生成的Jar包中-->
</goals>
</execution>
</executions>
</plugin>
<!-- 扫描项目下所有的文件 -->
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.*</include>
</includes>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.*</include>
</includes>
</resource>
</resources>
6.最外层的pom.xml里只需要写通用的引用,引入所有子模块,modules标签即可
7.多种环境信息mvn clean install -P test
<!-- 环境信息 -->
<profiles>
<!-- 标机开发环境 -->
<profile>
<id>dev</id>
<properties>
<activeProfile>dev</activeProfile>
<serviceactive>servicedev</serviceactive>
<businessactive>businessdev</businessactive>
</properties>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
</profile>
<!-- 测试环境 -->
<profile>
<id>test</id>
<properties>
<activeProfile>test</activeProfile>
<serviceactive>servicetest</serviceactive>
<businessactive>businesstest</businessactive>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<!-- 生产环境 -->
<profile>
<id>product</id>
<properties>
<activeProfile>product</activeProfile>
<serviceactive>serviceproduct</serviceactive>
<businessactive>businessproduct</businessactive>
</properties>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
</profile>
</profiles>
2.简单试验过的
使用springboot + assembly打包(自定义文件目录内容,灵活但复杂)
参考链接
spring-boot-assembly: Spring Boot项目使用maven-assembly-plugin根据不同环境打包成tar.gz或者zip
SpringCloud maven-assembly-plugin 多级目录打包 - 掘金
maven-assembly-plugin 插件多模块打包实例_xiaoxiaojavacsdn的博客-CSDN博客
将 Maven 中的多模块项目只打成一个 JAR 包-蒲公英云
springboot maven 多模块打包 jar 找不到mainClass 4小时血泪史_走码观花-CSDN博客_maven打包没有mainclass