【问题标题】:IntelliJ can't run gradle project due to missing Class由于缺少 Class,IntelliJ 无法运行 gradle 项目
【发布时间】:2015-01-15 09:11:01
【问题描述】:

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

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

“vaadinsharedwidgets”是项目的一个模块。根据我从错误中了解到的情况,IntelliJ 没有找到 ant,但这是有意的,因为我不使用 ant。它也不是传递依赖的一部分。同一个项目在 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'

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'
}

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

【问题讨论】:

  • Gradle 实际上包含 Ant,因此您可以重用现有的 Ant 任务。您没有包含您的 gradle 版本或版本。实际上,您没有包含错误之外的任何内容,这使得任何人都很难提供帮助。
  • 抱歉信息缺失。我添加了相关版本。
  • 请包含来自 vaadinsharedwidgets 模块的 build.gradle。
  • gradle build 是否可以从命令行工作?这将确定问题是否与 Gradle 或 Intellij 有关。 Intellij 社区版是否包含构建 Vaadin 项目所需的一切?据我所知,它缺少关键的网络内容。您可以免费试用 Ultimate 版 30 天。
  • 我添加了 build.gradle 文件及其依赖项。从命令行构建工作正常。该项目使用嵌入式码头,所以我想如果没有 IntelliJ 的任何应用程序服务器支持我很好。

标签: java intellij-idea gradle


【解决方案1】:

从菜单中选择File → Invalidate Caches / Restart,然后选择Invalidate and Restart。这解决了我的问题。

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

    • 你的意思是15.0.1吗?无论如何,我仍然有问题。
    • youtrack.jetbrains.com/issue/IDEA-147146 ; File / Invalidate Caches+Restart 似乎有帮助。
    • 缓存和重启无效 - 这可能是一个答案@MartinVysny
    【解决方案3】:

    经过一些修补和试错后,我发现 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' 
        }
    }
    

    使用 jetty9 代替旧版本的 vaadin-gradle 插件使用的 jetty8 是过时的 hack 的一部分。当前版本使用 9.2.2 似乎还不错。

    【讨论】:

      猜你喜欢
      • 2019-10-22
      • 2018-11-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-28
      • 2018-11-27
      • 2022-07-31
      相关资源
      最近更新 更多