intellij idea15搭建spring源码阅读环境
标签: 源码学习
环境准备
(1)下载intellij idea15
官网下载连接:https://www.jetbrains.com/idea/download/
建议下载Ultimate版本,这样对web开发的支持组件比较多,开发较为方便,有经济能力的建议支持正版,没有的话你懂的。
(2)下载jdk8,配置java环境
(3)clone spring源码
spring源码github地址:https://github.com/spring-projects/spring-framework
下载源码后别着急用idea打开,首先阅读源码中的import-into-idea.md文件,文件内容如下,按着一步步操作即可
Steps
Within your locally cloned spring-framework working directory:
1. Pre-compile spring-oxm
with ./gradlew cleanIdea :spring-oxm:compileTestJava
2. Import into IDEA (File->import project->import from external model->Gradle)
3. Set the Project JDK as appropriate (1.8+)
4. Exclude the spring-aspects
module (Go to File->Project Structure->Modules)
5. Code away
Known issues
-
spring-oxm
should be pre-compiled since it’s using repackaged dependencies (see *RepackJar tasks) -
spring-aspects
does not compile out of the box due to references to aspect types unknown to IDEA.
See http://youtrack.jetbrains.com/issue/IDEA-64446 for details. In the meantime, the ‘spring-aspects’
should be excluded from the overall project to avoid compilation errors. - While all JUnit tests pass from the command line with Gradle, many will fail when run from IDEA.
Resolving this is a work in progress. If attempting to run all JUnit tests from within IDEA, you will
likely need to set the following VM options to avoid out of memory errors:
-XX:MaxPermSize=2048m -Xmx2048m -XX:MaxHeapSize=2048m
(4)用idea打开spring源码 随便写了一个test,运行结果如下图所示:
问题:
(1)源码按照上面导入后,gradle build 也成功了,但是自己写测试代码可能还会报一些包找不到的问题,如图
这是由于idea打开spring源码后依赖没有正确配置,添加依赖即可解决
(2)如果依赖都正确配置了,但是程序还是无法运行,那可能是依赖顺序问题,详细可查阅这个博客
http://www.wurenny.com/2015/04/17/186