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

ssi*_*lar 15 java intellij-idea gradle

我只是尝试了IntelliJ,因为Eclipse再次让我恼火.我进口了我的gradle项目(jetty,vaadin),它进展顺利.但是当我尝试运行它时,我在"make"期间遇到以下错误消息:

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

"vaadinsharedwidgets"是该项目的一个模块.根据我从错误中理解,IntelliJ没有找到蚂蚁,但这是因为我不使用蚂蚁.它也不是传递依赖的一部分.同样的项目在eclipse中运行良好,并且在gradle工程中构建它没有任何问题.

更新:我刚刚在Eclipse中检查过,不知何故ant.jar在Eclipse的类路径中,但是我无法将它链接到任何项目.我想知道它是如何实现的.

Update2:缺少版本信息:

  • IntelliJ:v14.0.1 CE(无插件)
  • Gradle:2.2(通过包装器使用)
  • Java 8(1.8.0 b05)
  • Vaadin 7.3.4

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'
Run Code Online (Sandbox Code Playgroud)

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
}
Run Code Online (Sandbox Code Playgroud)

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'
}
Run Code Online (Sandbox Code Playgroud)

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

Mat*_*aun 10

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

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

  • https://youtrack.jetbrains.com/issue/IDEA-147146; 文件/无效缓存+重启似乎有所帮助. (6认同)
  • 缓存和重启无效 - 这应该是@MartinVysny的答案 (3认同)

ssi*_*lar 2

经过一些修补和尝试错误后,我发现 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' 
    }
}
Run Code Online (Sandbox Code Playgroud)

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