方法1. 使用idea创建 java项目
创建java项目的工作参考上一篇文章
安装Gradle,在IDEA中使用Gradle
https://www.jianshu.com/p/4a2693fbd056
1.1. 配置springboot,编辑build.gradle文件
plugins {
id 'java'
id "org.springframework.boot" version "2.4.2"
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
}
group 'test.gradle'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile 'org.springframework.boot:spring-boot-starter-web'
}
1.2. 创建一个springboot的启动类
package com;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@RestController
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class);
}
@RequestMapping("hello-gradle")
public String hello() {
return "hello gradle";
}
}
1.3. 启动项目,在浏览器打开url
说明项目创建、启动成功

image.png
方法2. 使用idea创建 spring initializer
new -> project -> spring initializer -> next -> 填写项目信息,type使用 Gradle Project -> next -> next -> finish

image.png

image.png

image.png
参考:
https://blog.csdn.net/weixin_40826349/article/details/96874172
https://www.jianshu.com/p/01588c396a29
方法3. 使用springboot官网生成项目:
在spring官网创建一个样板项目,然后下载,导入idea
https://start.spring.io/
参考:
注意:gradle和springboot是有版本对应关系的
我的idea是2018.3版本的,能支持gradle最大的版本是5.x.x。
我使用2.4.x版本的springboot时,项目可以正常编译和启动。

image.png
使用2.5.x版本的springboot时,编译报错

image.png
个人比较推荐使用方法1创建springboot项目。使用方法2、方法3创建springboot项目,很可能会因为idea、gradle、springboot之间的版本不兼容问题导致编译失败。到头来也还是要手动调整gradle-wrapper.properties、build.gradle。