zl程序教程

您现在的位置是:首页 >  后端

当前栏目

【错误记录】IntelliJ IDEA 编译 Groovy 项目报错 ( gradle-resources-test:XX: java.lang.NoClassDefFoundError: org )

JAVA错误IDEAgradle项目 报错 记录 编译
2023-06-13 09:18:00 时间

文章目录

一、报错信息


IntelliJ IDEA 编译 Groovy 代码报错 :

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

详细报错信息 :

Executing pre-compile tasks...
Loading Ant configuration...
Running Ant tasks...
Running 'before' tasks
Checking sources
Finished, saving caches...
gradle-resources-test:Groovy_Demo: java.lang.NoClassDefFoundError: org/apache/tools/ant/util/ReaderInputStream
Executing post-compile tasks...
Loading Ant configuration...
Running Ant tasks...
Synchronizing output directories...
2022/1/25 13:14 - Build completed with 1 error and 0 warnings in 259 ms

二、问题分析


出错的项目中 , build.gradle 配置信息如下 :

plugins {
    id 'groovy'
    id 'java'
}

group 'org.example'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    compile 'org.codehaus.groovy:groovy-all:3.0.5'
    testCompile group: 'junit', name: 'junit', version: '4.12'
}

重新创建项目 , build.gradle 如下 :

plugins {
    id 'groovy'
    id 'java'
}

group 'org.example'
version '1.0-SNAPSHOT'

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.codehaus.groovy:groovy-all:3.0.5'
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.0'
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
}

test {
    useJUnitPlatform()
}

三、解决方案


Groovy 工程中 , 出现 gradle-resources-test:Groovy_Demo: java.lang.NoClassDefFoundError: org/apache/tools/ant/util/ReaderInputStream 报错 ;

网上的方案是 在下面的界面中 , 删除 main / test , 然后清理 Excluded Folders , 使用后无效 ;

重新创建了一个新的 Groovy 项目 , 编译可以通过 , 拷贝 build.gradle 到出错项目中 , 然后 选择 " File / Invalidate Caches… " 选项 ,

点击 Invalidate and Restart 按钮 ;

重启后编译通过 ;