spring-framework
Build from Source
在windows中编译会出现几个问题
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':referencePdf'.
GC overhead limit exceeded
GC overhead limit exceeded : 说明GC有98%的时间在处理垃圾回收 需要增加java内存
解决方法
修改gradlew.bat中 GRADLE_OPTS 参数设置(按照个人情况设置,不必要设置这么大)
set GRADLE_OPTS=-XX:MaxMetaspaceSize=2048m -Xmx2048m -XX:MaxHeapSize=1024m %GRADLE_OPTS%
FAILURE: Build failed with an exception.
* What went wrong:
Failed to capture snapshot of input files for task 'distZip' during up-to-date check.
java.io.FileNotFoundException: D:\git\spring-framework\build\distributions\spring-framework-4.3.11.BUILD-SNAPSHOT-schema.zip (The system cannot find the file specified)...
linux 和windows 的区别导致查找文件时没有找到spring-framework-4.3.11.BUILD-SNAPSHOT-schema.zip
解决方法
修改build.gradle中的schemaZip方法
task schemaZip(type: Zip) {
group = "Distribution"
baseName = "spring-framework"
classifier = "schema"
description = "Builds -${classifier} archive containing all " +
"XSDs for deployment at http://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))
}
assert xsdFile != null
into (shortName) {
from xsdFile.path
}
}
}
}
替换为
task schemaZip(type: Zip) {
group = "Distribution"
baseName = "spring-framework"
classifier = "schema"
description = "Builds -${classifier} archive containing all " +
"XSDs for deployment at http://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
}
}
}
}
* What went wrong:
Execution failed for task ':spring-context-support:test'.
There were failing tests. See the report at: file:///D:/git/spring-framework/spring-context-support/build/reports/tests/index.html
打开提示的html发现有几条失败的test, 将提示错误的test中方法忽略或者删除
对JasperReportsUtils的test
JasperReportsUtils API介绍是 : 为CSV,HTML,PDF和XLS格式的报告提供了一套便利的方法.
对我们学习Spring源码没有影响
虽然现在提倡使用idea,但是笔者还是习惯使用eclipse
./import-into-eclipse.bat
转换为eclipse项目分5个步骤
1). 提示将要转换的项目需要 Eclipse + AJDT 推荐使用STS
2). 提示转换需要用到Gradle,第一次使用会下载
3). 提示将项目导入eclipse/STS
File > Import... > Existing Projects into Workspace
> When prompted for the 'root directory', provide %CURRENT_DIR%
> Press enter. You will see the modules show up under "Projects"
> All projects should be selected/checked. Click Finish.
> When the project import is complete, you should have no errors.
4). 生成Spring根目录文件
5). 按照步骤2再次导入根文件
6). 完成,提示连接github(IDE已经自动连接了)
在Wiki中找到Snapshot Builds,下载自己eclipse版本对应的Groovy插件
至此Spring的源码已经完成编译,可以进行开发及学习
参考原文 : http://www.jianshu.com/p/9205beaa0fe2