1、背景:
今天给项目打jar包时发现了一个打jar包失败的问题。原因是由于项目的公共包没有main方法导致打包失败,但是我们的公共模块确实不需要main方法,所以需要想办法去掉这项校验,经过查阅资料已解决,特此记录一下
2、错误:
错误内容如下:
[INFO] ------------------------------------------------------------------------[INFO] BUILD FAILURE[INFO] ------------------------------------------------------------------------[INFO] Total time: 1.729 s[INFO] Finished at: -07-09T21:00:11+08:00[INFO] ------------------------------------------------------------------------[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.6.4:repackage (repackage) on project yaomall-common: Execution repackage of goal org.springframework.boot:spring-boot-maven-plugin:2.6.4:repackage failed: Unable to find main class -> [Help 1][ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.[ERROR] Re-run Maven using the -X switch to enable full debug logging.[ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles:[ERROR] [Help 1] /confluence/display/MAVEN/PluginExecutionException[ERROR] [ERROR] After correcting the problems, you can resume the build with the command[ERROR] mvn <args> -rf :yaomall-common
3、解决方法在公共模块中的pom文件加入如下配置
方法一:
<plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><configuration><skip>true</skip></configuration></plugin></plugins>
方法二:
<plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><configuration><mainClass>none</mainClass><!-- 取消查找本项目下的Main方法:为了解决Unable to find main class的问题 --><classifier>execute</classifier> <!-- 为了解决依赖模块找不到此模块中的类或属性 --></configuration><executions><execution><goals><goal>repackage</goal></goals></execution></executions></plugin></plugins>
4、解决方案借鉴于如下博主(感谢博主):
/i402097836/article/details/116232418