依赖工具
我自己用的版本
ideaui2021
jdk1.8
maven(idea中配置)
gradle(gradle-7.0.2-bin.zip)
gradle下载地址 [https://gradle.org/next-steps/?version=7.0.2&format=bin](https://gradle.org/next-steps/?version=7.0.2&format=bin)
clone项目源码
从Springboot的GitHub仓库 https://github.com/spring-projects/spring-boot fork出自己仓库,便于后面源码阅读做笔记随时提交。这里我的版本是springboot-2.5.0 release版本
然后用在idea中从自己fork出来仓库中clone源码,clone完成后先停止掉idea的自动构建,因为需要修改一些gradle配置。
- 修改下载源
gradle\wrapper中的配置文件gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
#distributionUrl这个换成自己本地gradle-7.0.2-bin.zip地址
#distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-bin.zip
distributionUrl=file:///E:/soft/gradle-7.0.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2.buildSrc下的build.gradle ,需要修改这两个地方
plugins {
id "java-gradle-plugin"
//id "io.spring.javaformat" version "${javaFormatVersion}"
id "checkstyle"
}
repositories {
maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' }
maven { url 'https://maven.aliyun.com/nexus/content/repositories/jcenter' }
maven { url "https://repo.spring.io/plugins-release" }
mavenCentral()
gradlePluginPortal()
maven { url "https://repo.spring.io/release" }
}
3.buildSrc下的settings.gradle,修改这一个地方
repositories {
maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' }
maven { url 'https://maven.aliyun.com/nexus/content/repositories/jcenter' }
maven { url "https://repo.spring.io/plugins-release" }
mavenCentral()
gradlePluginPortal()
}
4.工程根目录下的build.gradle,添加一个,修改一处
// 添加这个,放在第一行
buildscript {
repositories {
maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' }
maven { url 'https://maven.aliyun.com/nexus/content/repositories/jcenter' }
maven { url "https://repo.spring.io/plugins-release" }
}
}
allprojects {
group "org.springframework.boot"
repositories {
maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' }
maven { url 'https://maven.aliyun.com/nexus/content/repositories/jcenter' }
mavenCentral()
if (version.contains('-')) {
maven { url "https://repo.spring.io/milestone" }
}
if (version.endsWith('-SNAPSHOT')) {
maven { url "https://repo.spring.io/snapshot" }
}
}
configurations.all {
resolutionStrategy.cacheChangingModulesFor 0, "minutes"
}
}
5.工程根目录下的seetings.gradle,修改一处
repositories {
maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' }
maven { url 'https://maven.aliyun.com/nexus/content/repositories/jcenter' }
mavenCentral()
gradlePluginPortal()
maven {
url 'https://repo.spring.io/plugins-release'
}
if (version.endsWith('-SNAPSHOT')) {
maven { url "https://repo.spring.io/snapshot" }
}
}
6.指定idea中gradle下载路径,这里最好要指定下,因为默认会下载到C盘用户目录下,项目依赖比较大,实测下完需要2G。
完成以上操作就可以开始gradle构建了,过程比较慢,需要耐性等耐。当然过程中可能会遇到一些报错,就需要自己一步步填坑了,比较废人。
挑一个我就遇到这个错误记录下
git checkout成功,但是检查时报错,报某个包下得文件名过长。
这个需要打开git bash,执行下面这个命令即可
git config --system core.longpaths true