1. 基础环境
名称 | 说明 |
---|---|
JDK 1.8.0_144 | JDK版本 |
IntelliJ IDEA 2020.1 | IDEA版本 |
Gradle-4.10.3 | Gradle版本 |
spring-framework-5.1.x | Spring源码版本 |
2. 准备前提
- JDK环境
- IntelliJ IDEA环境
- Gradle环境
2.1 搭建JDK环境
参考:https://blog.csdn.net/qq_43625140/article/details/108871133
2.2 搭建IDEA环境
参考:https://blog.csdn.net/qq_43625140/article/details/108691749
2.3 搭建Gradle环境
- Spring源码基于Gradle构建,需要搭建Gradle环境,这里选用【gradle-4.10.3-all.zip】进行搭建,下载地址如下:
Gradle下载:https://services.gradle.org/distributions
-
下载好gradle后直接解压缩即可,这里解压目录为【D:\DevelopmentTool\gradle\gradle-4.10.3】
-
配置gradle环境变量,新建GRADLE_HOME变量,配置Gradle解压目录
-
在Path变量中添加【%GRADLE_HOME%\bin】
- cmd命令行测试gradle是否安装成功,输入命令【gradle -version】出现gradle版本如下:
3. 源码搭建
- 从GitHub下载Spring源码,这里选择从分支【5.1.x】下载zip包进行解压,下载地址如下:
Spring仓库:https://github.com/spring-projects/spring-framework
-
下载完成后进行解压缩导入IDEA
-
修改gradle/wrapper/gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
# 使用自己的gradle
distributionUrl=file:///D:/DevelopmentTool/gradle/gradle-4.10.3-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
- 注释gradle/docs.gradle文件中如下部分:
因为Spring源码基于Linux环境发布GitHub仓库,在Windows环境下需要做出部分修改
//dokka {
// dependsOn {
// tasks.getByName("api")
// }
// doFirst {
// classpath = subprojects.collect { project -> project.jar.outputs.files.getFiles() }.flatten()
// classpath += files(subprojects.collect { it.sourceSets.main.compileClasspath })
//
// }
// moduleName = "spring-framework"
// outputFormat = "html"
// outputDirectory = "$buildDir/docs/kdoc"
//
// sourceDirs = files(subprojects.collect { project ->
// def kotlinDirs = project.sourceSets.main.kotlin.srcDirs.collect()
// kotlinDirs -= project.sourceSets.main.java.srcDirs
// })
// externalDocumentationLink {
// url = new URL("https://docs.spring.io/spring-framework/docs/$version/javadoc-api/")
// packageListUrl = new File(buildDir, "api/package-list").toURI().toURL()
// }
// externalDocumentationLink {
// url = new URL("https://projectreactor.io/docs/core/release/api/")
// }
// externalDocumentationLink {
// url = new URL("https://www.reactive-streams.org/reactive-streams-1.0.1-javadoc/")
// }
//}
//asciidoctor {
// // only output PDF documentation for non-SNAPSHOT builds
// if (!project.getVersion().toString().contains("BUILD-SNAPSHOT")) {
// dependsOn 'asciidoctorPdf'
// }
// sources {
// include '*.adoc'
// }
// resources {
// from(sourceDir) {
// include 'images/*', 'stylesheets/*', 'tocbot-3.0.2/*'
// }
// }
// logDocuments = true
// backends = ["html5"]
// options doctype: 'book', eruby: 'erubis'
// attributes 'icons': 'font',
// 'idprefix': '',
// 'idseparator': '-',
// docinfo: '',
// revnumber: project.version,
// sectanchors: '',
// sectnums: '',
// 'source-highlighter': 'coderay@', // TODO switch to 'rouge' once supported by the html5 backend
// stylesdir: 'stylesheets/',
// stylesheet: 'main.css',
// 'spring-version': project.version
//}
//task schemaZip(type: Zip) {
// group = "Distribution"
// baseName = "spring-framework"
// classifier = "schema"
// description = "Builds -${classifier} archive containing all " +
// "XSDs for deployment at https://springframework.org/schema."
// duplicatesStrategy 'exclude'
// moduleProjects.each { subproject ->
// def Properties schemas = new Properties();
//
// subproject.sourceSets.main.resources.find {
// (it.path.endsWith("META-INF/spring.schemas") || it.path.endsWith("META-INF\\spring.schemas"))
// }?.withInputStream { schemas.load(it) }
//
// for (def key : schemas.keySet()) {
// def shortName = key.replaceAll(/http.*schema.(.*).spring-.*/, '$1')
// assert shortName != key
// File xsdFile = subproject.sourceSets.main.resources.find {
// (it.path.endsWith(schemas.get(key)) || it.path.endsWith(schemas.get(key).replaceAll('\\/','\\\\')))
// }
// assert xsdFile != null
// into (shortName) {
// from xsdFile.path
// }
// }
// }
//}
- 在gradle/docs.gradle文件中添加如下部分:
task schemaZip(type: Zip) {
group = "Distribution"
baseName = "spring-framework"
classifier = "schema"
description = "Builds -${classifier} archive containing all " +
"XSDs for deployment at https://springframework.org/schema."
duplicatesStrategy 'exclude'
moduleProjects.each { subproject ->
def Properties schemas = new Properties();
subproject.sourceSets.main.resources.find {
it.path.endsWith("META-INF\\spring.schemas")
}?.withInputStream { schemas.load(it) }
for (def key : schemas.keySet()) {
def shortName = key.replaceAll(/http.*schema.(.*).spring-.*/, '$1')
assert shortName != key
File xsdFile = subproject.sourceSets.main.resources.find {
it.path.endsWith(schemas.get(key).replaceAll('\\/','\\\\'))
}
assert xsdFile != null
into (shortName) {
from xsdFile.path
}
}
}
}
- 修改build.gradle文件,修改内容如下:
Spring需要很多依赖,设置阿里云镜像环境便于加快依赖的下载。
repositories {
maven { url "https://maven.aliyun.com/nexus/content/groups/public/" }
maven { url "https://maven.aliyun.com/nexus/content/repositories/jcenter" }
mavenCentral()
maven { url "https://repo.spring.io/libs-spring-framework-build" }
maven { url "https://repo.spring.io/milestone" }
maven { url "https://repo.spring.io/plugins-release" }
}
- 根据【import-into-idea.md】文件的描述,先编译spring-oxm模块
- 构建全部模块