问题
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.
回答1:
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')
}
回答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'
}
回答3:
If you added dependency later:
Right click on project -> gradle -> refresh
来源:https://stackoverflow.com/questions/53664575/how-to-import-external-dependencies-in-gradle