Home > front end >  build.gradle cannot resolve symbol 'groovy.json.JsonSlurper'
build.gradle cannot resolve symbol 'groovy.json.JsonSlurper'

Time:02-22

I can't resolve the groovy.json.JsonSlurper in the build.gradle file with Intellij, does anyone know how to fix it?


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);
}

enter image description here

CodePudding user response:

You missing the needed dependency.

Add org.codehaus.groovy:groovy-json:3.0.9 in dependencies section so ti will look like

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

And then you can test with CLI as gradle sample or ./gradlew sample and it will return {a=b}

  • Related