1.安装jdk1.8,略过。
2.安装gradle-4.10.3
springframework5.1.x源码构建工具是gradle-4.10.3版本。
点击链接从gradle官网下载4.10.3版本的二进制包
下载后解压
添加环境变量,GRADLE_HOME 为安装目录,GRADLE_USER_HOME为类似maven的本地仓库。
添加path
打开cmd查看是否安装成功执行
grade -v
最最最最重要的点!
为了加速构建过程中依赖包的下载速度,使用阿里云镜像。
在gradle安装目录下的init.d文件夹下创建init.gradle文件
init.gradle输入如下内容:
allprojects{
repositories {
def REPOSITORY_URL = 'http://maven.aliyun.com/nexus/content/groups/public/'
all { ArtifactRepository repo ->
def url = repo.url.toString()
if ((repo instanceof MavenArtifactRepository) && (url.startsWith('https://repo1.maven.org/maven2')||url.startsWith('https://repo.maven.apache.org/maven2') || url.startsWith('https://jcenter.bintray.com'))) {
project.logger.lifecycle 'Repository ${repo.url} replaced by $REPOSITORY_URL .'
remove repo
}
}
maven {
url REPOSITORY_URL
}
}
}
3.下载springframework5.1.x.zip
从github下载spring源码包,git clone或者download zip都可以。
这里提供百度网盘下载spring源码zip
链接:https://pan.baidu.com/s/1Eq1FpnPAHVg8ir9f_F4xfg
提取码:8fd4
解压缩。
4.导入Idea
先打开idea,close当前project。
选择import project
选择解压的spring源码
选择gradle
选择下面6个地方
Gradle VM options:
-XX:MaxPermSize=2048m -Xmx2048m -XX:MaxHeapSize=2048m
点击Finish开始导入
导入之后idea开始构建spring。
然后开始下载spring的依赖包。
导入完成后,每个模块文件夹上会出现蓝色图标即表示导入成功。
构建完成之后开始编译。
5.编译
1)修改docs.gradle。
在编译之前将下图所示的文件中的dokka和asciidoctor两个任务注释掉,不然在生成javadoc时可能会报错。
网上有人说因为spring是在Linux下开发的路径与windows不一致,还需要修改task schemaZip里面涉及的文件路径,但其实spring源码包里已经修改好了不需要我们自己修改了。如果你的源码还没修改那就改成下面的。
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
}
}
}
}
2)如果你不想一次编译所有的模块,那就按readme.md所指示的编译那几个模块就行了。点击右侧gradle。一次编译spring-core,spring-oxm,spring-context。就ok了,结束了。
3)使用gradle wrapper编译一次编译所有模块。
将刚安装的gradle打成zip包。
1.修改spring-framework-5.1.x\gradle\wrapper\gradle-wrapper.properties文件的distributionUrl为刚才打的压缩gradle zip包路径。
distributionUrl=file\:/S://gradle.zip
打开idea的terminal。
进入到spring根目录,执行命令
gradlew build -x test
等待
编译成功。