一、新建Gradle Project,点下一步输入项目名
1、在Gradle distribution选择Local installation directory,填写Gradle Home路径
E:\gradle-2.11
2、在Advanced options里填写Gradle user home directory,这只存放gradle下载的jar包的路径,默认在C盘的User文件夹下
E:\gradle
3、点下一步,在点击finish就完成项目创建
二、build.gradle文件
apply plugin: 'java'
// In this section you declare where to find the dependencies of your project
repositories {
// Use 'jcenter' for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter() //gradle默认的中央仓库
mavenCentral() //自己添加的Maven中央仓库
}
// In this section you declare the dependencies for your production and test code
dependencies {
// The production code uses the SLF4J logging API at compile time
compile 'org.slf4j:slf4j-api:1.7.14'
compile 'com.google.code.gson:gson:2.6.2' //添加自己要用的jar包依赖
// Declare the dependency for your favourite test framework you want to use in your tests.
// TestNG is also supported by the Gradle Test task. Just change the
// testCompile dependency to testCompile 'org.testng:testng:6.8.1' and add
// 'test.useTestNG()' to your build script.
testCompile 'junit:junit:4.12'
}
右键项目,选择Gradle--》Refresh Gradle Project将自动下载依赖
至此,就可以使用gson包了