Maven多模块打包 #SpringBoot
三步曲
SmallArea (不要在父模块加 spring-boot-starter-test 依赖)
-- distributed-smallarea-common
-- distributed-smallarea-service
-- user-service (需要打包插件)
-- store-service(需要打包插件)
不管是什么模块,打包前:
1、保证良好的关系下,父模块、公共都不需要打包插件,只有能启动的具体模块才需要加插件,还要加打包类型 即:
<packaging>jar</packaging>
...
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions> <!--没有它,springboot打包出来的jar运行报错-->
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>1.3.6</version>
<configuration>
<repository>${project.artifactId}</repository>
<buildArgs>
<JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE>
</buildArgs>
</configuration>
</plugin>
</plugins>
</build>
2、然后对要打包的模块的父模块进行安装(有几个父模块就打几个):切换到父模块根目录下执行: mvn clean install 或 mvn -f 指定的位置 clean install
3、对公共模块进行安装 ,安装方法根父模块安装方法一样
-------------------------
Some problems were encountered while processing the POMs: [ERROR] Invalid packaging for parent POM bo.zhao:myutil:1.0-SNAPSHOT (E:\IDEA\myutil\pom.xml), must be "pom" but is "jar" @ bo.zhao:myutil:1.0-SNAPSHOT, E:\IDEA\myutil\pom.xml
解决办法:
parent工程的pom.xml文件的project节点下加入如下节点(父工程打包需要是pom):
<packaging>pom</packaging>