Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 230
user619804 Avatar asked Feb 24 '17 08:02

user619804


People also ask

What is a JsonArray?

JsonArray represents an immutable JSON array (an ordered sequence of zero or more values). It also provides an unmodifiable list view of the values in the array. A JsonArray object can be created by reading JSON data from an input source or it can be built from scratch using an array builder object.

How do I add a dependency in gradle?

To add a dependency to your project, specify a dependency configuration such as implementation in the dependencies block of your module's build.gradle file.


1 Answers

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

implementation 'org.json:json:20171018'
like image 68
David Miller Avatar answered Sep 28 '22 11:09

David Miller