【转】Gradle的使用教程
Gradle的使用教程
一、相关介绍
Gradle是一个好用的构建工具 ,使用它的原因是:
- 配置相关依赖代码量少,不会像maven一样xml过多
- 打包编译测试发布都有,而且使用起来方便
- 利用自定义的任务可以完成自己想要的功能
二、安装
下载地址 https://services.gradle.org/distributions/ ,下载你所需要对应的版本,我这里下载的是gradle-6.6.1-bin.zip。
下载后解压到你想要的目录即可,然后设置环境变量:
GRADLE_HOME
%GRADLE_HOME%\bin;
在cmd模式下查看,出现以下信息证明安装成功:
gradle -v
然后我们可以在在环境变量里配置gradle默认的仓库地址(和maven不太一样):
GRADLE_USER_HOME

build.gradle 文件
buildscript { repositories { mavenCentral() } dependencies { classpath 'org.springframework.boot:spring-boot-gradle-plugin:2.7.9' classpath 'io.spring.dependency-management:io.spring.dependency-management.gradle.plugin:1.1.0' } } plugins { id 'java' } apply plugin: 'org.springframework.boot' apply plugin: 'io.spring.dependency-management' group = 'com.example' version = '0.0.1-SNAPSHOT' sourceCompatibility = '8' configurations { compileOnly { extendsFrom annotationProcessor } } repositories { mavenCentral() } dependencies { implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' implementation 'org.springframework.boot:spring-boot-starter-web' compileOnly 'org.projectlombok:lombok' developmentOnly 'org.springframework.boot:spring-boot-devtools' annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor' annotationProcessor 'org.projectlombok:lombok' testImplementation 'org.springframework.boot:spring-boot-starter-test' } tasks.named('test') { useJUnitPlatform() }
使用自定义属性,需要使用双引号括起来EL表达式,${}, $不加{}都可以,例如:
buildscript { ext { springBootVersion = '2.7.9' springDependencyManagementVersion = '1.1.0' } repositories { mavenCentral() } dependencies { classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}" classpath "io.spring.dependency-management:io.spring.dependency-management.gradle.plugin:$springDependencyManagementVersion" } } plugins { id 'java' } apply plugin: 'org.springframework.boot' apply plugin: 'io.spring.dependency-management' group = 'com.example' version = '0.0.1-SNAPSHOT' sourceCompatibility = '8' configurations { compileOnly { extendsFrom annotationProcessor } } repositories { mavenCentral() } dependencies { implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' implementation 'org.springframework.boot:spring-boot-starter-web' compileOnly 'org.projectlombok:lombok' developmentOnly 'org.springframework.boot:spring-boot-devtools' annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor' annotationProcessor 'org.projectlombok:lombok' testImplementation 'org.springframework.boot:spring-boot-starter-test' } tasks.named('test') { useJUnitPlatform() }
IDEA如何正确配置Gradle? GRADLE_USER_HOME 和 Gradle user home的区别
配置 Gradle (IDEA) 环境的坑
Plugin [id: 'org.springframework.boot', version: '2.1.6.RELEASE'] was not found in any of the following sources: - Gradle Core Plugins (plugin is not in 'org.gradle' namespace) - Plugin Repositories (could not resolve plugin artifact 'org.springframework.boot:org.springframework.boot.gradle.plugin:2.1.6.RELEASE') Searched in the following repositories: Gradle Central Plugin Repository
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 字符编码:从基础到乱码解决