1、安装jdk
安装jdk1.8以上版本,配好环境变量,spring最新的代码已经使用jdk8的一些新特性,故必须jdk8或以上版本。
2、安装git客户端
由于spring源代码已经托管GitHub
3、安装grandle
下载安装gradle 3.0 以上版本(我安装的是4.4的版本),也需要配置好环境变量
下载地址:http://services.gradle.org/distributions/
验证安装环境:
4、下载spring源码
下载spring源代码,我直接下载到了:E:\spring-framework
如果你的机器内容足够大,则可以考虑把 gradlew.bat 的jvm参数调大一点
5、阅读 import-into-idea.md
import-into-idea.md 中的第一步我没有执行成功,然后我就放弃了直接执行了 gradlew命令,你可以按这个步骤折腾一下!
1. Precompile `spring-oxm` with `./gradlew cleanIdea :spring-oxm:compileTestJava`
6、执行gradlew命令
看到如下输出你距离spring源码成功导入idea还有一步之遥
E:\spring-framework>gradlew
Downloading https://services.gradle.org/distributions/gradle-3.4-bin.zip
................................................................................
................................................................................
...........................................................................
Unzipping C:\Users\Administrator\.gradle\wrapper\dists\gradle-3.4-bin\aeufj4znod
ijbvwfbsq3044r0\gradle-3.4-bin.zip to C:\Users\Administrator\.gradle\wrapper\dis
ts\gradle-3.4-bin\aeufj4znodijbvwfbsq3044r0
Starting a Gradle Daemon (subsequent builds will be faster)
Generating JAR file 'gradle-api-3.4.jar'
Cleaned up directory 'E:\spring-framework\buildSrc\build\classes\main'
Cleaned up directory 'E:\spring-framework\buildSrc\build\resources\main'
:buildSrc:clean
:buildSrc:compileJava NO-SOURCE
:buildSrc:compileGroovy
:buildSrc:processResources
:buildSrc:classes
:buildSrc:jar
:buildSrc:assemble
:buildSrc:compileTestJava NO-SOURCE
:buildSrc:compileTestGroovy NO-SOURCE
:buildSrc:processTestResources NO-SOURCE
:buildSrc:testClasses UP-TO-DATE
:buildSrc:test NO-SOURCE
:buildSrc:check UP-TO-DATE
:buildSrc:build
Download https://repo.spring.io/plugins-release/org/sonarsource/scanner/gradle/s
onarqube-gradle-plugin/2.2.1/sonarqube-gradle-plugin-2.2.1.pom
Download https://repo.spring.io/plugins-release/org/sonarsource/scanner/api/sona
r-scanner-api/2.8/sonar-scanner-api-2.8.pom
Download https://repo.spring.io/plugins-release/org/sonarsource/scanner/api/sona
r-scanner-api-parent/2.8/sonar-scanner-api-parent-2.8.pom
Download https://repo.spring.io/plugins-release/org/sonarsource/parent/parent/36
/parent-36.pom
POM relocation to an other version number is not fully supported in Gradle : xml
-apis:xml-apis:2.0.2 relocated to xml-apis:xml-apis:1.0.b2.
Please update your dependency to directly use the correct version 'xml-apis:xml-
apis:1.0.b2'.
Resolution will only pick dependencies of the relocated element. Artifacts and
other metadata will be ignored.
Download https://repo.spring.io/plugins-release/org/sonarsource/scanner/gradle/s
onarqube-gradle-plugin/2.2.1/sonarqube-gradle-plugin-2.2.1.jar
Download https://repo.spring.io/plugins-release/org/jruby/jruby-complete/9.1.8.0
/jruby-complete-9.1.8.0.jar
Download https://repo.spring.io/plugins-release/org/sonarsource/scanner/api/sona
r-scanner-api/2.8/sonar-scanner-api-2.8.jar
Download https://repo.spring.io/plugins-release/xml-apis/xml-apis/2.0.2/xml-apis
-2.0.2.jar
Cleaned up directory 'E:\spring-framework\buildSrc\build\classes\main'
Cleaned up directory 'E:\spring-framework\buildSrc\build\resources\main'
:help
Welcome to Gradle 3.4.
To run a build, run gradlew <task> ...
To see a list of available tasks, run gradlew tasks
To see a list of command-line options, run gradlew --help
To see more detail about a task, run gradlew help --task <task>
BUILD SUCCESSFUL
Total time: 3 mins 28.144 secs
7、导入idea
导入的过程需要一定的时间,这期间需要下载很多的依赖包,保证你的网络可用,(最好能访问 Google!),需要耐心等待,人品爆发一次就能成功!!!
8、编译构建
9、运行调试
经过上面的 8 个步骤之后基本上就可以直接运行 spring 的 Testcase 了,如果有少部分类报错,那么你就直接进入到相关类中,一般都是没有添加依赖,你可以直接使用自动添加依赖的方式排除报错!
10、新版本问题
新版spring下载下来可能遇到如下的问题:
(1)、SpringObjenesis 类里面显示部分类找不到
(2)、cglib的代理包可能找不到
11、问题解决方案
产生这个问题的根本原因是spring依赖了 Objenesis,但是spring未直接将源代码打包进去
(1)、下载spring发布的新版本zip包。
http://repo.springsource.org/libs-release-local/org/springframework/spring/
(2)、解压以上spring-framework-4.3.9.RELEASE-dist.zip
(3)、解压 spring-core-4.3.9.RELEASE.jar
(4)、手动打jar包
jar cvf spring-cglib-repack-3.2.4.jar org\springframework\cglib
jar cvf spring-objenesis-repack-2.4.jar org\springframework\objenesis
(5)、将以上两个手动打的jar包放到:spring-core/build/libs/ 下
(6)、特别注意:
今天又折腾了一次源代码下载导入idea,发现上面的jar包放到 libs 下不起作用了。
通过排查,发现新版本的 Spring 已经把上面的两个jar包的版本号修改了,如下:
解决办法:把打好的jar包版本号修改一下就 OK 了。
(7)、大家不愿意折腾的也可以来这下载:
https://pan.baidu.com/s/1hsGkInq 密码:560k
经过以上步骤新版本的报错问题即可解决,实在搞不定的可以加我QQ:787141854 交流……