java 由于缺少类,IntelliJ 无法运行 gradle 项目

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26989932/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 11:00:28  来源:igfitidea点击:

IntelliJ can't run gradle project due to missing Class

javaintellij-ideagradle

提问by ssindelar

I just gave IntelliJa try, because Eclipseannoyed me again. I imported my gradleproject(jetty, vaadin) and it went quite smoothly. But when I tried to run it I encountered the following error message during "make":

我刚刚尝试了IntelliJ,因为Eclipse 又惹恼了我。我导入了我的gradle项目(jetty、vaadin)并且进行得很顺利。但是当我尝试运行它时,我在“make”期间遇到了以下错误消息:

Error:gradle-resources-test:vaadinsharedwidgets: java.lang.NoClassDefFoundError: org/apache/tools/ant/util/ReaderInputStream

错误:gradle-resources-test:vaadinsharedwidgets:java.lang.NoClassDefFoundError:org/apache/tools/ant/util/ReaderInputStream

"vaadinsharedwidgets" is a module of the project. From what I understand from the error, IntelliJ doesn't find ant, but this is intended because I don't use ant. It also not part of the transitive dependencies. The same project runs in eclipse fine and also building it in gradle works without any problems.

“vaadinsharedwidgets”是项目的一个模块。根据我对错误的理解,IntelliJ 没有找到 ant,但这是因为我不使用 ant。它也不是传递依赖的一部分。同一个项目在 eclipse 中运行良好,并且在 gradle 中构建它也没有任何问题。

Update:I just checked in Eclipse and somehow the ant.jar is on the classpath in Eclipse but I can't link it to any project. I wonder how it got there.

更新:我刚刚检查了 Eclipse,不知何故 ant.jar 在 Eclipse 的类路径上,但我无法将它链接到任何项目。我想知道它是如何到达那里的。

Update2:Missing version information:

Update2:缺少版本信息:

  • IntelliJ: v14.0.1 CE (no plugins)
  • Gradle: 2.2 (used via wrapper)
  • Java 8 (1.8.0 b05)
  • Vaadin 7.3.4
  • IntelliJ:v14.0.1 CE(无插件)
  • Gradle:2.2(通过包装器使用)
  • Java 8 (1.8.0 b05)
  • 瓦丁 7.3.4


build.gradle:

build.gradle

apply from: 'http://nexus/gradle/vaadin.gradle'
apply from: 'http://nexus/gradle/java8.gradle'

version = '1.1'

description = "Gemeinsame Vaadin-Widgets"

vaadin.widgetset  'net.xyz.vaadinsharedwidgets.VaadinsharedWidgetsWidgetset'

dependencies {
    compile project(':ibhtheme')
    compile 'com.vaadin:vaadin-server:' + vaadin.version
    compile 'com.vaadin:vaadin-client:' + vaadin.version
}

jar{
    // Include source in jar
    from sourceSets.main.allJava
}

sourceSets.main.resources.srcDir  'src/main/webapp'


vaadin.gradle:

vaadin.gradle:

apply from: 'http://plugins.jasoft.fi/vaadin.plugin?version=0.9.2'

configurations {
    def conf = 'vaadin-client'
    def sources = project.sourceSets.main
    def testSources = project.sourceSets.test

    if (!project.configurations.hasProperty(conf)) {
        project.configurations.create(conf)

        sources.compileClasspath += project.configurations[conf]
        testSources.compileClasspath += project.configurations[conf]
        testSources.runtimeClasspath += project.configurations[conf]

        project.configurations[conf].exclude group: 'org.eclipse.jetty' 
    }
}


vaadin {
    version '7.3.4'
    push true
}


java8.gradle:

java8.gradle:

apply plugin: 'java'

sourceCompatibility = 1.8
targetCompatibility = 1.8

group = 'net.xyz'

dependencies {
    compile 'org.slf4j:slf4j-api:1.7.5'
    compile 'com.google.guava:guava:16.0.1'
    compile 'org.springframework:spring-context:4.0.3.RELEASE'

    testCompile 'org.testng:testng:6.8.7'
    testCompile 'org.mockito:mockito-all:1.9.5'
    testCompile 'org.easytesting:fest-assert-core:2.0M10'
    testCompile 'org.springframework:spring-test:4.0.3.RELEASE'
}

Adding ant as an additional dependency to the module doesn't work.

将 ant 作为附加依赖项添加到模块不起作用。

采纳答案by ssindelar

After some tinkering and try-and-error I found that the following code in the vaadin.gradle was the culprit and removed it:

经过一些修补和尝试错误后,我发现 vaadin.gradle 中的以下代码是罪魁祸首并将其删除:

configurations {
    def conf = 'vaadin-client'
    def sources = project.sourceSets.main
    def testSources = project.sourceSets.test

    if (!project.configurations.hasProperty(conf)) {
        project.configurations.create(conf)

        sources.compileClasspath += project.configurations[conf]
        testSources.compileClasspath += project.configurations[conf]
        testSources.runtimeClasspath += project.configurations[conf]

        project.configurations[conf].exclude group: 'org.eclipse.jetty' 
    }
}

It was part of an outdated hack to use jetty9 instead of jetty8, which was used by older versions of the vaadin-gradle plugin. The current version uses 9.2.2 which seems to be fine.

它是使用 jetty9 而不是 jetty8 的过时黑客的一部分,后者被旧版本的 vaadin-gradle 插件使用。当前版本使用 9.2.2 似乎没问题。

回答by Matthias Braun

I encountered the same error in a Java project with multiple subprojects in IntelliJ 14.

我在 IntelliJ 14 中有多个子项目的 Java 项目中遇到了同样的错误。

Updating to 15.0.1, refreshing the Gradle projects via Views → Tool Windows → Gradlein IntelliJ and restarting fixed the issue.

更新到 15.0.1,通过Views → Tool Windows → GradleIntelliJ刷新 Gradle 项目并重新启动修复了问题。

回答by neu242

Choose File → Invalidate Caches / Restartfrom the menu and select Invalidate and Restart. That fixed the issue for me.

选择File → Invalidate Caches / Restart从菜单中选择Invalidate and Restart。那为我解决了这个问题。