idea导入spring源码

一、工作环境准备

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

二、下载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

三、下载安装gradle

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


 1、第一步:下载包,这边我们可以选择complete下载

idea导入spring源码_第1张图片

    2, 下载完包后我们解压文件,当然这边的路径我们可以自定义,如果是linux 或macos系统,则按如下步骤执行,如果是windows系统见下面2.1步骤
      


idea导入spring源码_第2张图片

  2.1  windows系统操作步骤

    idea导入spring源码_第3张图片


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结构以及源码了



  

你可能感兴趣的:(一起开始学java,啦)