Idea 搭建Spring源码环境的超详细教程

本篇主要讲解如何使用Ideal 搭建Spring的源码环境,想必大家都会多多少少去看过Spring的部分源码,一般我们都是直接点进某个Spring类 然后Idea上面去下载 ,但是确实比较麻烦,而且不能添加自己对源码的注释 理解 ,本篇就来解决这个问题,手把手使用Idea 搭建Spring framework ,并且直接在Spring framework项目中添加我们自己的module 来验证环境是否正确。 本过程会比较耗时 而且容易出错 慢慢来吧。

1. clone spring-framework 项目

1.1 找到github spring-framwwork 项目

先登录github 找到 spring-framework项目

https://github.com/spring-projects

image-20200924100101919

我选择的是 5.0.x

image-20200924100152972

如果你觉得你网速可以,那你可以直接从 github clone 下来, 我这里先把项目传到 gitee

1.2 fork 到gitee 码云

image-20200924100520958

拉取你要的 分支 git clone -b 分支

image-20200924101002192

2. 查看 import-into-idea.md 文件

在下载的源码中 有一个文件是 import-into-idea 的 md文件 里面有关于导入 idea需要的 注意事项,我们来打开它

The following has been tested against IntelliJ IDEA 2016.2.2

## Steps

_Within your locally cloned spring-framework working directory:_

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

## Known issues

1. `spring-core` and `spring-oxm` should be pre-compiled due to repackaged dependencies.
See `*RepackJar` tasks in the build and https://youtrack.jetbrains.com/issue/IDEA-160605).
2. `spring-aspects` does not compile due to references to aspect types unknown to
IntelliJ IDEA. See https://youtrack.jetbrains.com/issue/IDEA-64446 for details. In the meantime, the
'spring-aspects' can be excluded from the project to avoid compilation errors.
3. While JUnit tests pass from the command line with Gradle, some may fail when run from
IntelliJ IDEA. Resolving this is a work in progress. If attempting to run all JUnit tests from within
IntelliJ 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. If you invoke "Rebuild Project" in the IDE, you'll have to generate some test
resources of the `spring-oxm` module again (`./gradlew :spring-oxm:compileTestJava`) 


## Tips

In any case, please do not check in your own generated .iml, .ipr, or .iws files.
You'll notice these files are already intentionally in .gitignore. The same policy goes for eclipse metadata.

## FAQ

Q. What about IntelliJ IDEA's own [Gradle support](https://confluence.jetbrains.net/display/IDEADEV/Gradle+integration)?

A. Keep an eye>image-20200908133100199

image-20200908133315577

2.2 再导入导 idea 中

会开始下载 Gradle 构建工具 等,会根据 gradle-wrapper.properties 中的指定版本下载,最好不要修改它的版本

image-20201012092914514

Idea导入 选择文件夹

image-20200924103331680

选择使用Gradle

![image-20200924103346932](/Users/johnny/Library/Application Support/typora-user-images/image-20200924103346932.jpg)

静静的等待

image-20200908131416428

image-20200908131504088

Idea 搭建Spring源码环境的超详细教程

扫一扫手机访问