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結構以及源碼了