1

New to java development here. I'm using gradle in eclipse.

I want to import the JSONParser. In my code I have:

    import org.json.simple.parser.JSONParser;

and in build.gradle I have:

repositories {

    mavenCentral()
}

dependencies {

    compile 'com.googlecode.json-simple:json-simple:1.1.1'


}

However, when I try to build I get:

int/MainApp.java:7: error: cannot find symbol
import org.json.simple.parser;
                      ^
  symbol:   class parser
  location: package org.json.simple
1 error

What's going on here? I think I don't understand exactly how gradle works.

doctopus
  • 5,349
  • 8
  • 53
  • 105
  • can you change it `compile group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1' ` – Shiva Dec 07 '18 at 07:49

3 Answers3

2

Try it, it may helpful for you:

 buildscript {
   ext {
     springBootVersion = '2.1.0.RELEASE'
   }
   repositories {
     mavenCentral()
   }
   dependencies {
     classpath("org.springframework.boot:spring-boot-gradle- 
     plugin:${springBootVersion}")
  }
}

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

 group = 'com.xyz'
 version = '0.0.1-SNAPSHOT'
 sourceCompatibility = 1.8

 repositories {
  mavenCentral()
 }

 dependencies {
   compile 'com.googlecode.json-simple:json-simple:1.1.1'
 }
Shiva Kumar N
  • 371
  • 3
  • 11
2

If you added dependency later:

Right click on project -> gradle -> refresh

enter image description here

Shiva
  • 1,962
  • 2
  • 13
  • 31
2

If you have the jar files in a folder, for example in the lib folder in root directory, add the following to your gradle build

dependencies 
{
compile files('libs/something_local.jar')
}
venkat
  • 442
  • 5
  • 17