IntelliJ IDEA 升级后 NoClassDefFoundError [英] NoClassDefFoundError after IntelliJ IDEA upgrade

查看:169
本文介绍了IntelliJ IDEA 升级后 NoClassDefFoundError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我创建了一个使用 IntelliJ IDEA 和 Gradle 进行依赖管理的新项目.解决项目所需的所有依赖项并运行它后,我收到以下错误:

Recently I created a new project using IntelliJ IDEA and Gradle for dependency management. After resolving all the dependencies needed by the project and running it I get the following error:

java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication
    at com.some.fancy.name.Application.main(Application.java:13)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 6 more

问题仅出现在已解析依赖项中的类中(我也使用 Guava 中的 Cache 使用简单的 main 程序进行了尝试).导致错误的类如下:

The problem occurs only with the classes from the resolved dependencies (I tried it also with a simple main program using Cache from Guava). The class causing the error is the following:

@SpringBootApplication
public class Application {
    public static void main(String... args) {
        SpringApplication.run(Application.class, args);
    }
}

所有字段都显示正确的颜色(注释是黄色的,没有什么是红色的),IntelliJ 在 External Libraries 目录中有所有解析的依赖项.我正在使用绿色的运行"箭头来启动项目.

All the fields are shown correct colour (annotations are yellow, nothing is red), IntelliJ has all the resolved dependencies in the External Libraries directory. I'm using the green "run" arrow to start the project.

从命令行使用 gradle 时,创建一个胖 jar 然后一切正常.我已经尝试过无效缓存/重新启动",从存储库中多次提取项目,清除 gradle 缓存,手动删除所有依赖项,尝试使用社区版,终极版运行它,运行已经工作的旧项目前段时间(现在不工作).

When using gradle from the command line, creating a fat jar then everything works fine. I already tried "Invalidate Caches/Restart", pulled the project several times from the repository, cleared the gradle caches, removed all the dependencies by hand, tried to run it using the Community Edition, the Ultimate Edition, running older projects which already worked some time ago (and don't work now).

这是否与将 IntelliJ IDEA 更新到 2016.3.4, build 163.12024.16 有某种关系?

Could it be somehow related to updating IntelliJ IDEA to 2016.3.4, build 163.12024.16?

推荐答案

这是 IntelliJ IDEA 中特定于 Gradle 3.4 及更高版本的已知问题:

It's a known issue in IntelliJ IDEA that is specific to Gradle 3.4 and later versions:

  • IDEA-167412 Gradle 3.4-rc-1 changes compile dependencies to provided
  • original bug report in the Gradle project with more details
  • comment from the responsible developer regarding "Create Module per source set" option and how Gradle integration works in IntelliJ IDEA

它已经在 IntelliJ IDEA 2017.12016.3.6.

如果您不能或不想更新 IntelliJ IDEA,您也可以使用 Gradle 3.3 或更早版本作为解决方法.

You can also use Gradle 3.3 or older as a workaround if you can't or don't want to update IntelliJ IDEA.

这篇关于IntelliJ IDEA 升级后 NoClassDefFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆