我無法使用 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);
}
在此處輸入影像描述
uj5u.com熱心網友回復:
您缺少所需的依賴項。
添加部分org.codehaus.groovy:groovy-json:3.0.9,dependencies所以 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 sampleor進行測驗./gradlew sample,它會回傳{a=b}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/432345.html
