You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Gradle重载Java插件报错,含org.json依赖配置求助

问题

使用Gradle开发Java插件时,点击Gradle重载按钮后出现错误:

无法处理'/Applications/IntelliJ IDEA CE.app/Contents/plugins/gradle/lib/gradle-api-impldep-8.0.jar'中的条目'org/gradle/internal/impldep/com/amazonaws/services/kms/model/transform/CreateGrantRequestProtocolMarshaller.class'

当前build.gradle配置如下:

plugins {
    id 'java'
}

group = 'org.centoricraft'
version = '1.0-SNAPSHOT'

repositories {
    mavenCentral()
    maven { url = "https://repo.codemc.org/repository/maven-public/" }
    maven {
        name = "spigotmc-repo"
        url = "https://hub.spigotmc.org/nexus/content/repositories/snapshots/"
    }
    maven {
        name = "sonatype"
        url = "https://oss.sonatype.org/content/groups/public/"
    }
    maven {
        url = uri("https://repo.opencollab.dev/main")
    }
}

dependencies {
    compileOnly "dev.jorel:commandapi-bukkit-core:9.0.1"
    compileOnly "org.spigotmc:spigot-api:1.19.4-R0.1"
    compileOnly("org.geysermc.floodgate:api:2.2.2-SNAPSHOT")
    compile 'org.json:json:20210307'
}

def targetJavaVersion = 17
java {
    def javaVersion = JavaVersion.toVersion(targetJavaVersion)
    sourceCompatibility = javaVersion
    targetCompatibility = javaVersion
    if (JavaVersion.current() < javaVersion) {
        toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion)
    }
}

tasks.withType(JavaCompile).configureEach {
    if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) {
        options.release = targetJavaVersion
    }
}

processResources {
    def props = [version: version]
    inputs.properties props
    filteringCharset 'UTF-8'
    filesMatching('plugin.yml') {
        expand props
    }
}
解决方案
  • 清理Gradle缓存:执行./gradlew clean build --refresh-dependencies,强制刷新依赖并清理本地缓存,避免损坏的缓存文件导致加载失败。
  • 对齐Gradle版本:检查项目gradle/wrapper/gradle-wrapper.properties中的distributionUrl,确保其版本与报错中的8.0一致,比如设置为distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip。
  • 重置IDE缓存:关闭IDEA,删除项目根目录下的.idea和build文件夹后重新导入项目;也可通过File -> Invalidate Caches...清理IDE缓存并重启。
  • 排查依赖问题:将compile 'org.json:json:20210307'改为compileOnly,减少不必要的依赖打包;执行./gradlew dependencies查看依赖树,排查是否存在重复或冲突依赖。
  • 升级IDE版本:如果使用旧版IDEA,升级到最新稳定版,解决IDE与Gradle版本的兼容性问题。

内容的提问来源于stack exchange,提问作者Nopfp

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.21 15:27:35