【问题标题】:build.gradle cannot resolve symbol 'groovy.json.JsonSlurper'build.gradle 无法解析符号 \'groovy.json.JsonSlurper\'
【发布时间】:2023-01-09 14:46:51
【问题描述】:

我无法使用 Intellij 解析 build.gradle 文件中的 groovy.json.JsonSlurper,有人知道如何修复吗?


plugins {
    id 'java'
}

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

repositories {
    mavenCentral()
}

dependencies {
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
}

test {
    useJUnitPlatform()
}



task sample() {
    doLast {
        sample();
    }
}

import groovy.json.JsonSlurper
def sample(){
    def json = new JsonSlurper().parseText('{"a":"b"}')
    println(json);
}

【问题讨论】:

    标签: java gradle groovy


    【解决方案1】:

    您缺少所需的依赖项。

    dependencies部分添加org.codehaus.groovy:groovy-json:3.0.9,这样ti看起来像

    dependencies {
        testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
        testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
        implementation 'org.codehaus.groovy:groovy-json:3.0.9'
    }
    

    然后你可以使用 CLI 作为 gradle sample./gradlew sample 进行测试,它将返回 {a=b}

    【讨论】:

    • 谢谢!解决了它,我把它放在 buildscript 块中,并且只将它与 Gradle Script 一起使用。
    猜你喜欢
    • 2013-11-15
    • 1970-01-01
    • 1970-01-01
    • 2014-04-28
    • 2021-06-30
    • 2018-11-11
    • 2017-02-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多