简体   繁体   English

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

[英]IntelliJ can't run gradle project due to missing Class

I just gave IntelliJ a try, because Eclipse annoyed me again. 我只是尝试了IntelliJ ,因为Eclipse再次让我恼火。 I imported my gradle project(jetty, vaadin) and it went quite smoothly. 我进口了我的gradle项目(jetty,vaadin),它进展顺利。 But when I tried to run it I encountered the following error message during "make": 但是当我尝试运行它时,我在“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. “vaadinsharedwidgets”是该项目的一个模块。 From what I understand from the error, IntelliJ doesn't find ant, but this is intended because I don't use ant. 根据我从错误中理解,IntelliJ没有找到蚂蚁,但这是因为我不使用蚂蚁。 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. 同样的项目在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. 更新:我刚刚在Eclipse中检查过,不知何故ant.jar在Eclipse的类路径中,但是我无法将它链接到任何项目。 I wonder how it got there. 我想知道它是如何实现的。

Update2: Missing version information: Update2:缺少版本信息:

  • IntelliJ: v14.0.1 CE (no plugins) IntelliJ:v14.0.1 CE(无插件)
  • Gradle: 2.2 (used via wrapper) Gradle:2.2(通过包装器使用)
  • Java 8 (1.8.0 b05) Java 8(1.8.0 b05)
  • Vaadin 7.3.4 Vaadin 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:

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:

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作为附加依赖项添加到模块不起作用。

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 → Gradle in IntelliJ and restarting fixed the issue. 更新到15.0.1,通过Views → Tool Windows → Gradle刷新Gradle项目Views → Tool Windows → Gradle IntelliJ中的Views → Tool Windows → Gradle并重新启动修复了问题。

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. 它是使用jetty9而不是jetty8的过时黑客攻击的一部分,后者被旧版本的vaadin-gradle插件使用。 The current version uses 9.2.2 which seems to be fine. 当前版本使用9.2.2似乎没问题。

Choose File → Invalidate Caches / Restart from the menu and select Invalidate and Restart . 从菜单中选择File → Invalidate Caches / Restart ,然后选择Invalidate and Restart That fixed the issue for me. 这解决了我的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM