整理下最近编译Spring源码的过程以及中间的一些问题解决方法。
一、下载
可以从GitHub直接clone,也可以下载release包
1、clone方式
https://github.com/spring-projects/spring-framework.git
2、release包
注意:clone方式获取的是spring framework的master版本,而release包可以选择不同版本
推荐使用release包方式获取,选择4.3.x的版本
二、编译
在Spring-framework目录或spring-framework-4.3.x-RELEASE目录打开命令窗口,执行
gradlew build -x test
进行编译,-x 选项跳过测试
三、导入Eclipse
在Spring-framework目录或spring-framework-4.3.x-RELEASE目录打开命令窗口,执行
gradle cleanEclipse eclipse -x :eclipse
进行项目转换。
转换完成,安装File -> Import -> Existing Projects into Workspace,即可进行导入。
四、问题整理
1、编译失败,提示信息为:
Failed to capture snapshot of input files for task ':distZip' property 'rootSpec$1$3' during up-to-date check.
> Failed to create MD5 hash for file 'D:\source\Spring-framework\build\distributions\spring-framework-4.3.14.BUILD-SNAPSHOT-schema.zip'.
出现该问题,是因为windows环境下的路径寻找问题。
解决方法:修改项目中gradle配置的Zip路径
如果是master版本,则修改
Spring-framework\gradle\docs.gradle文件
如果是4.3.x版本,则修改
Spring-framework\build.gradle文件
查找 task schemaZip(type: Zip) 模块
it.path.endsWith("META-INF/spring.schemas")
修改为
it.path.endsWith("META-INF\\spring.schemas")
it.path.endsWith(schemas.get(key))
修
改为
it.path.endsWith(schemas.get(key).replaceAll('\\/','\\\\'))
2、导入Eclipse后报错,提示GroovyDynamicElementReader这个类不存在
这是因为Eclipse缺少Groovy插件
解决方法:
在eclipse的 Help -> Install New Software 中,添加groovy的下载连接:
http://dist.springsource.org/milestone/GRECLIPSE/e4.4/
选择Groovy-Eclipse(Required),开始下载,下载完后,重启eclipse,即可。
3、导入Eclipse后报错,提示
The type java.util.concurrent.Flow$Publisher cannot be resolved. It is indirectly referenced from required .class files
解决方法:master分枝需要使用jdk9,如果是4.3.x版本的话,使用jdk8即可
这也是前面推荐下载release包的一个原因