在 fork 官方源碼 到自己的倉(cāng)庫(kù)后(fork 的好處是方便自己試驗(yàn)和注釋?zhuān)?將其 git clone 下來(lái), 因平時(shí)工作用的是 idea 就想用 idea 作為工具。
clone 下來(lái)后可以看到根目錄下有2個(gè)指引文件
說(shuō)明 import-into-idea.md 中寫(xiě)明了導(dǎo)入 idea 的步驟
Within your locally cloned spring-framework working directory:
- Pre-compile spring-oxm with ./gradlew cleanIdea :spring-oxm:compileTestJava
- Import into IDEA (File->import project->import from external model->Gradle)
- Set the Project JDK as appropriate (1.8+)
- Exclude the spring-aspects module (Go to File->Project Structure->Modules)
- Code away
- 需要預(yù)先編譯 spring-oxm 這個(gè) xml 的對(duì)象映射模塊,命令:
./gradlew cleanIdea :spring-oxm:compileTestJava - 導(dǎo)入到 idea (文件 -> 導(dǎo)入項(xiàng)目 -> 從外部導(dǎo)入模型 -> Gradle
- 設(shè)置項(xiàng)目 jdk 版本為 1.8
- 將模塊 spring-aspects 從項(xiàng)目中排除 (文件 -> 項(xiàng)目結(jié)構(gòu) -> 模塊)
- 好了,可以滾去擼代碼了
這邊我是直接用 idea 打開(kāi)項(xiàng)目, 然后在 terminal 中執(zhí)行 ./gradlew cleanIdea :spring-oxm:compileTestJava

接著是漫長(zhǎng)的等待。。。 9分多鐘

但是我在刷新 gradle 的時(shí)候還碰到一個(gè)問(wèn)題 (我是用的 4.3.x 分支,master 分支不會(huì)有這個(gè)問(wèn)題)
Gradle sync failed: Cause: org/gradle/listener/ActionBroadcast
參考 https://stackoverflow.com/questions/44363124/gradle-sync-failed-cause-org-gradle-listener-actionbroadcast 的解答,把 build.gradle 里邊的
plugins {
id "org.sonarqube" version "1.1"
}
改為
plugins {
id "org.sonarqube" version "2.6.1"
}
然后等插件加載完就好了
最終,idea 中項(xiàng)目目錄的類(lèi)別也都識(shí)別出來(lái)了

步驟還是很明確的,只是需要加載的時(shí)間較長(zhǎng)
突然~~ 又想玩玩 eclipse了
源碼本身不是 eclipse 能識(shí)別的格式, 需要先執(zhí)行下根目錄下的 import-into-eclipse.sh 腳本
sh import-into-eclipse.sh 也是要等一會(huì),會(huì)生成一些 eclipse 工程需要的文件 ,然后 eclipse 導(dǎo)入的時(shí)候就能識(shí)別了
我是新下載的 eclipse,所以在導(dǎo)入前需要先裝好 gradle 的插件,直接在 help -> eclipse marketplace 里邊安裝

然后 file -> import -> gradle 選擇代碼目錄就好了,然后可能會(huì)出現(xiàn) spring-beans-groovy 這個(gè)模塊報(bào)錯(cuò),原因是因?yàn)闆](méi)有安裝 groovy 的編譯器導(dǎo)致的,同樣在 marketplace 中安裝


下載 spring 插件, 在官網(wǎng) https://spring.io/tools/sts/all 中選擇eclipse 版本對(duì)應(yīng)的插件包


然后,help -> install new software 選擇下載好是 zip 文件

選 Spring IDE 相關(guān)

安裝完重啟后,可以在 window -> show view -> other 中看到多了幾個(gè)
