1、下载spring源码
github地址: https://github.com/spring-projects/spring-framework 选择一个目录,在这个目录右键-Git Bash Here,然后一直等待下载完成 ``` git clone https://github.com/spring-projects/spring-framework.git ``` ![](https://img2018.cnblogs.com/blog/1373276/201903/1373276-20190306112522591-2050562816.png) 下载完成之后我们进入spring-framework看看spring的源码分布: ![](https://img2018.cnblogs.com/blog/1373276/201903/1373276-20190306112846624-1396564245.png)2、编译
由于Spring源码是采用Gradle这种自动化构建工具构建的,因此需要安装 Gradle ``` gradle -v ``` ![](https://img2018.cnblogs.com/blog/1373276/201903/1373276-20190306112717445-1034396233.png) 如果使用IDEA作为开发工具,那么需要认真阅读 import-into-idea.md,它告诉了你导入IDEA的步骤,按照以下步骤来操作即可: > 1. Precompile `spring-oxm` with `./gradlew :spring-oxm:compileTestJava` > 2. Import into IntelliJ (File -> New -> Project from Existing Sources -> Navigate to directory -> Select build.gradle) > 3. When prompted exclude the `spring-aspects` module (or after the import via File-> Project Structure -> Modules) > 4. Code away等待IDEA项目构建完成...
在构建过程中发现报超时错误,此时需要找到build.gradle文件,将maven仓库改成阿里云的仓库
buildscript {
repositories {
maven { url "http://maven.aliyun.com/nexus/content/groups/public/" }
}
dependencies {
classpath("io.spring.gradle:propdeps-plugin:0.0.9.RELEASE")
classpath("org.asciidoctor:asciidoctorj-pdf:1.5.0-alpha.16")
}
}
改成之后IDEA自动继续构建,又报以下错误
最后在一篇博客中找到解决方法,在repositories 下面添加以下仓库 maven { url "http://repo.springsource.org/plugins-release" }
最终的配置如下:
buildscript {
repositories {
maven { url "http://maven.aliyun.com/nexus/content/groups/public/" }
maven { url "http://repo.springsource.org/plugins-release" }
}
dependencies {
classpath("io.spring.gradle:propdeps-plugin:0.0.9.RELEASE")
classpath("org.asciidoctor:asciidoctorj-pdf:1.5.0-alpha.16")
}
}
构建成功!
排除 spring-aspects 项目
选中spring-aspects,右键-Load/Unload Modules,进行如下设置:
至此,IDEA构建spring的源码环境就配置好了!