parent有两个module,其中module-web依赖module-api,
parent
module-api
module-web
其中module-api是一些基础的东西,module-web是将来要部署的项目,
maven项目中,parent的pom里定义了插件:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
这意味着所有parent的子项目都会引用spring-boot-maven-plugin这个插件,
它的作用是在maven package打包后进行二次打包,为了生成可执行的jar包,
而module-api中只是一些基础api,没有springboot的启动类,
打包时会报错:
Unable to find main class.
在module-api的pom添加如下配置:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>none</mainClass>
</configuration>
</plugin>
这次module-api不报错了,但是到module-web时报错:
Failed to read artifact descriptor for com.xxx:jar: 1.0.0、
Compilation failure: Compilation failure: 程序包com.xxx不存在。
说明module-api打的包有问题,
原因是module-api不是要部署的项目,
不能让spring-boot-maven-plugin来二次打包,
那么我们要如何排除这个插件呢?
将module-api的配置改为:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
其中
skip>true</skip
表示在当前模块跳过这个插件。
refs:
阿利波波:springBoot子项目中排除掉定义在Parent中的插件
small onion:springboot工程maven打包 Compilation failure 程序包不存在踩坑
fjh1997:如何在maven的子模块里排除父模块的plugin以及报错