Gradle Build - Not Able to Import Org. Json

I have a problem where I’m trying to include org.json as a dependency in my gradle/spring boot project. In my build.gradle I have

dependencies {
    compile("org.springframework.boot:spring-boot-starter-web")
    compile("org.springframework.boot:spring-boot-starter-security")
    compile("org.json:json:20141113")
}

But in the editor window it looks like IntelliJ is not able to import org.json - it’s unable to find the package

What’s weird is that I can run the gradle ‘build’ task without errors in IntelliJ, and I can run

./gradlew clean build && java -jar build/libs/MyApp-0.1.0.jar

and it works fine.

Is this a ‘fat jar’ problem? I’m not sure it is because org.json is definitely not in my class path on the command line. Any advice appreciated.

4

2 Answers

I was able to successfully download json in my gradle dependencies:

implementation 'org.json:json:20171018'
2

As some mentioned, mvnrepository provides snippet for different Build systems. After you choose your desired version, in the middle of the page, select Gradle as build system, copy and paste the snippet in your build.gradle file, section dependencies in your java project.

// 
compile group: 'org.json', name: 'json', version: '20180813'
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

James H. Sterling

James H. Sterling

Environmental Science & Climate Journalist

James Sterling reports on renewable energy developments, climate policy, ecological conservation, and green tech innovations around the globe.

Share this article
Twitter Facebook Pinterest