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

enter image description here

enter image description here

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

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like