gradle 无需提前下载,项目创建之后,会根据gradle-wrapper.properties 自动下在对应配置的 gradle

一、基本配置

1、gradle-wrapper.properties

  1. distributionBase=GRADLE_USER_HOME
  2. distributionPath=wrapper/dists
  3. distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.1-bin.zip
  4. zipStoreBase=GRADLE_USER_HOME
  5. zipStorePath=wrapper/dists

2、gradle.build 配置

  1. buildscript {
  2. // 自定义脚本资源
  3. repositories {
  4. // 脚本仓库
  5. maven { url "https://plugins.gradle.org/m2/" }
  6. }
  7. dependencies {
  8. // 这个插件包含了 org.springframework.boot 和 io.spring.dependency-management
  9. classpath "org.springframework.boot:spring-boot-gradle-plugin:2.6.6"
  10. }
  11. }
  12. plugins {
  13. id 'java'
  14. }
  15. apply plugin: 'io.spring.dependency-management'
  16. apply plugin: 'org.springframework.boot'
  17. group 'com.supkingx'
  18. version '1.0-SNAPSHOT'
  19. repositories {
  20. mavenLocal()
  21. maven { url 'https://maven.aliyun.com/repository/public/' }
  22. mavenCentral()
  23. }
  24. dependencies {
  25. testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.0'
  26. testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
  27. implementation group: 'org.springframework.boot', name: 'spring-boot-starter-web'
  28. }
  29. test {
  30. useJUnitPlatform()
  31. }

二、代码

  1. @SpringBootApplication
  2. public class Application {
  3. public static void main(String[] args) {
  4. SpringApplication.run(Application.class);
  5. }
  6. }
  1. @RestController
  2. @RequestMapping("/testController")
  3. public class TestController {
  4. @GetMapping("test")
  5. public String test(String param) {
  6. return param + " ok!";
  7. }
  8. }

三、IDEA 配置

image.png