idea导入spring源码

1、工做环境准备

  •      须要安装jdk1.8  (由于编译项目的时候有一个-XX:MaxMetaspaceSize=1024m的参数须要jdk1.8才支持,不然会报错
  •      须要安装git , 将会从git上下载spring源码

2、下载spring源码

        
      从git上切出项目
git clone git://github.com/SpringSource/Spring-framework.git

    切出的spring项目中咱们能够看到这些文件
      

     
    由于用的是idea,咱们接下来简单看下spring源码导入idea的指导文件,打开 import-into-idea.md文件,以下:
    
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 http://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](http://confluence.jetbrains.net/display/IDEADEV/Gradle+integration)?

A. Keep an eye on http://youtrack.jetbrains.com/issue/IDEA-53476

      主要的步骤已经用红色标记了,经过第一条(红色标记字中),咱们看到spring源码架构是须要依赖gradle管理的,那咱们须要先安装一下gradle

3、下载安装gradle

       到  https://gradle.org/install/  下载gradle  ,  咱们仍是直接看下他给我提供的文档来安装gradle


 一、第一步:下载包,这边咱们能够选择complete下载


    2, 下载完包后咱们解压文件,固然这边的路径咱们能够自定义,若是是linux 或macos系统,则按以下步骤执行,若是是windows系统见下面2.1步骤
      



  2.1  windows系统操做步骤

   


3, 好了,经过上面步骤咱们已经安装了gradle,接下来咱们须要配置环境变量(这个就不作过多介绍了,相似jdk环境变量配置)


4,配置完环境变量事后,咱们能够检测一下gradle是否安装成功,直接执行

gradle -v

  若是有版本信息输出,说明安装成功了


四, 编译spring 代码

Spring-framework目录下,咱们能够看到编译命令,咱们直接执行便可

   若是是linux或macos系统,则执行如下命令
 
./gradlew cleaIdea :spring-oxm:compileTestJava

     若是是windows系统,则执行如下命令
gradlew.bat cleanIdea :spring-oxm:compileTestJava

 

五,导入到idea之中


(1)打开IDEA,选择File->New->Project From Existing Sources…

(2)选中Spring-framework文件夹,OK->Import project from external model

(3)选中Gradle,点击Next,而后点击Finish,等待IDEA导入便可。


至此,spring源码就已经导入到idea工程中了,咱们也能够经过源码来看看spring结构以及源码了