//构建脚本(给脚本用的脚本)
buildscript {
//存储一个属于gradle的变量,整个工程都能用,可通过gradle.ext.springBootVersion使用
ext {
springBootVersion = '2.1.2.RELEASE'
}
/*配置仓库地址,从而找到外部依赖
按照你在文件中(build.gradle)仓库的顺序寻找所需依赖(如jar文件),
如果在某个仓库中找到了,那么将不再其它仓库中寻找
*/
repositories {
//mavenLocal()本地库,local repository(${user.home}/.m2/repository)
mavenCentral()//maven的中央仓库
//阿里云Maven远程仓库
maven { url "http://maven.aliyun.com/nexus/content/groups/public/" }
}
/*配置springboot插件加载
*/
dependencies {
// classpath 声明说明了在执行其余的脚本时,ClassLoader 可以使用这些依赖项
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
//使用以下插件
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'//jvm版本要求
// 定义仓库
repositories {
maven{url 'http://maven.aliyun.com/nexus/content/groups/public/'}
maven{url 'https://mvnrepository.com/'}
mavenCentral()
}
// 定义依赖:声明项目中需要哪些依赖
dependencies {
compile 'org.springframework.boot:spring-boot-starter'
compile('org.springframework.boot:spring-boot-starter-web')//引入web模块,springmvc
compile 'org.springframework.boot:spring-boot-starter-test'
}
springboot之build.gradle文件详解
Gradle构建脚本详解
最新推荐文章于 2025-10-11 10:59:00 发布
本文详细解析了Gradle构建脚本的结构与配置,包括如何设置全局变量、定义仓库地址、配置Spring Boot插件及依赖项。通过具体示例展示了如何应用插件、指定项目元数据、设置JVM兼容性以及管理项目依赖。
2292





