一.下载Gradle并配置
下载地址:http://services.gradle.org/distributions/ ,并配置环境变量如下:
1.新建GRADLE_HOME变量,设置文件的安装路径:
2.新建GRADLE_USER_HOME变量,设置gradle的本地仓库:
3.编辑Path变量,设置bin目录:
4.进入cmd,验证输入:gradle -v
二.Eclipse使用Gradle
1.首先需添加gradle插件(省略)
2.添加gradle属性
Eclipse -> Window -> Preferences -> Gradle -> Local installation -> 选择gradle安装目录 -> 选择gradle本地仓库目录 -> Apply
3.创建Gradle工程(步骤省略)
build.gradle配置文件如下:
buildscript {
ext{
springBootVersion = '2.1.7.RELEASE'
}
repositories {
maven{ url 'http://nexus.d17w.cn:9092/nexus/content/groups/public'}
maven{ url 'http://repo.spring.io/libs-milestone'}
}
dependencies {
classpath( "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath ( "io.spring.gradle:dependency-management-plugin:1.0.8.RELEASE")
classpath ( "com.bmuschko:gradle-cargo-plugin:2.6.1")
}
}
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'com.bmuschko.cargo'
apply plugin: 'com.bmuschko.cargo-base'
sourceCompatibility = 1.8
targetCompatibility = 1.8
version = '1.0.0'
tasks.withType(JavaCompile){
options.encoding = "UTF-8"
}
def env = System.getProperty("package.environment") ?: "dev"
repositories {
maven{ url 'http://nexus.d17w.cn:9092/nexus/content/groups/public'}
maven{ url 'http://repo.spring.io/libs-milestone'}
}
dependencies {
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web'
testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test'
testCompile group: 'junit', name: 'junit'
}
4.创建主启动类验证
@RestController
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class,args);
}
@RequestMapping("/")
String home() {
return "hey!JokerMan!";
}
}
访问localhost:8080