相关推荐recommended
Maven打包失败--Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:no found...
作者:mmseoamin日期:2023-12-21

1、问题还原,无论怎样操作,打包都是失败

Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.3.4.RELEASE:repackage (repackage) on project guigu-common: Execution repackage of goal org.springframework.boot:spring-boot-maven-plugin:2.3.4.RELEASE:repackage failed: Unable to find main class -> [Help 1]

[ERROR]

 2、这个问题,相信不少搬砖民工都遇到过。网上有很多解决的方案,也许有的可以解决,有的不能解决。在这里我罗列几种大家的方案:

① 注释掉 父工程的 plugin

首先,我的maven版本是 3.8.5;

引入的 pring-boot-starter-parent版本号为2.3.4.RELEASE;

最初怀疑这俩地方需要调整。

最后跟着网上的教程,把父pom中的maven-plugin注释掉之后,就成功了。

此处我仍然保留调整上面俩版本的意见,我只是觉着这次恰巧解决了问题而已。
Maven打包失败--Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:no found...,第1张

②  此项目不需要做打包,只需要提供公共镜像作为依赖,有两种方案:

添加spring-boot启动类

将pom.xml中的spring-boot-maven-plugin相关配置注释掉

pom.xml中spring-boot-maven-plugin相关配置修改为普通的maven--plugin配置即可

对于不需要添加启动类的服务模块,去掉该模块中pom.xml的maven打包插件spring-boot-maven-plugin

在此项目上,找个文件夹随意创建个main函数,基本就可以解决掉。

③ 清理IDEA缓存

File -> Invalidate Caches

④ 添加版本号

首先打开pom.xml文件进行查看

Ctrl+F搜索spring-boot-starter-parent

找到spring-boot-starter-parent这一行。

下面一行就是版本号。

    org.springframework.boot

    spring-boot-starter-parent

    2.1.1.RELEASE

    


复制 版本号

然后修改

将上面查找到的版本号粘贴到报错的那一行下面即可。

效果:

      org.springframework.boot

      spring-boot-maven-plugin

        2.1.1.RELEASE

 

 

⑤ pom中添加报错中提示的 repackage


        org.springframework.boot
        spring-boot-maven-plugin
        
            
                
                    repackage
                
            
        

 以上6种方案基本可以解决你的问题了。但是不巧的是,我遇到的问题上面的方案都不能解决,在这里跟大家分享下我的踩坑经历,血淋淋的教训,折磨了我几个小时!!!

前提提醒:如果你当前的模块不需要打包jar出来发布,以上的②方案就可以帮你解决。

不巧的是,你用的也是maven父子工程结构,这就导致以上的方案近乎全部失效(反正我没有成功),那么你需要了解父子工程的一些设计,这里就不多说了。

废话不多说,直接上干货:

一、首先你需要在父pom上 进行clean,清理下所有的缓存

Maven打包失败--Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:no found...,第2张

二、接着继续操作上图中的package ,就等待着一路  build。。。success就好了。

|

|

|

果真这样,恭喜你,成功解决问题。成功的同学可以略过了、、、、你也可以继续、、、

接着你会发现,那个失败的模块诡异般的又出现的错误,异常是这样的:Plugin ‘org.springframework.boot:spring-boot-maven-plugin:‘ not found,大概的意思就是你的打包工具在尝试打包时不能找打模块的main函数。

大家不要被这个异常蒙蔽,虽然说没有找到main。但是我们的appliation中已经有main函数也有run方法,你只需要,操作一下这里:

Maven打包失败--Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:no found...,第3张

没错,就是重新编译一下,让target下面生成class文件就好了。这时你只需要操作 pom 的package就可以打包了。切记:不要再次clean,因为一旦执行clean,class文件就会消失,打包还会出错。这是一次痛苦的踩坑,但是同样汗水的付出,换来了问题的解决,值得。

最后插播一条广告,喜欢研究技术,爱好技术的同学,可以加群!

Maven打包失败--Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:no found...,第4张