Java 如何在gradle中导入外部依赖项?

Java 如何在gradle中导入外部依赖项?,java,eclipse,gradle,Java,Eclipse,Gradle,这里是java开发的新手。我在eclipse中使用gradle 我想导入JSONParser。在我的代码中,我有: import org.json.simple.parser.JSONParser; 在build.gradle中,我有: repositories { mavenCentral() } dependencies { compile 'com.googlecode.json-simple:json-simple:1.1.1' } 但是,当我尝试构

这里是java开发的新手。我在eclipse中使用gradle

我想导入JSONParser。在我的代码中,我有:

    import org.json.simple.parser.JSONParser;
在build.gradle中,我有:

repositories {

    mavenCentral()
}

dependencies {

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


}
但是,当我尝试构建时,我得到:

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

这是怎么回事?我想我不太明白格拉德尔是怎么工作的

试试看,它可能会对您有所帮助:

 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'
 }

尝试一下,它可能会对您有所帮助:

 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'
 }

如果以后添加了依赖项:

右键单击项目->渐变->刷新


如果以后添加了依赖项:

右键单击项目->渐变->刷新


如果jar文件位于文件夹中,例如根目录中的lib文件夹中,请将以下内容添加到gradle构建中

dependencies 
{
compile files('libs/something_local.jar')
}

如果jar文件位于文件夹中,例如根目录中的lib文件夹中,请将以下内容添加到gradle构建中

dependencies 
{
compile files('libs/something_local.jar')
}

我不知道格拉德尔是怎么工作的。我需要下载jar吗?你这是什么意思?意思是“窗口->首选项->常规->键”,然后进行构建和清理,它将清除并导入所有依赖项。我不确定gradle是如何工作的。我需要下载jar吗?你的意思是什么?意味着进入“窗口->首选项->常规->键”并进行构建和清理,它将清除并导入所有依赖项。你能更改它吗编译组:'com.googlecode.json simple',名称:'json simple',版本:'1.1.1'你能更改它吗编译组:'com.googlecode.json simple',名称:“json简单”,版本:“1.1.1”