在 fork 官方源碼 到自己的倉庫后(fork 的好處是方便自己試驗和注釋)朦肘, 將其 git clone 下來, 因平時工作用的是 idea 就想用 idea 作為工具嘱蛋。
clone 下來后可以看到根目錄下有2個指引文件說明 import-into-idea.md 中寫明了導入 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
- 需要預先編譯 spring-oxm 這個 xml 的對象映射模塊蚯姆,命令:
./gradlew cleanIdea :spring-oxm:compileTestJava
- 導入到 idea (文件 -> 導入項目 -> 從外部導入模型 -> Gradle
- 設(shè)置項目 jdk 版本為 1.8
- 將模塊 spring-aspects 從項目中排除 (文件 -> 項目結(jié)構(gòu) -> 模塊)
- 好了,可以滾去擼代碼了
這邊我是直接用 idea 打開項目洒敏, 然后在 terminal 中執(zhí)行 ./gradlew cleanIdea :spring-oxm:compileTestJava
接著是漫長的等待龄恋。。凶伙。 9分多鐘
但是我在刷新 gradle 的時候還碰到一個問題 (我是用的 4.3.x 分支郭毕,master 分支不會有這個問題)
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 中項目目錄的類別也都識別出來了
步驟還是很明確的显押,只是需要加載的時間較長
突然~~ 又想玩玩 eclipse了
源碼本身不是 eclipse 能識別的格式, 需要先執(zhí)行下根目錄下的 import-into-eclipse.sh
腳本
sh import-into-eclipse.sh
也是要等一會傻挂,會生成一些 eclipse 工程需要的文件 乘碑,然后 eclipse 導入的時候就能識別了
我是新下載的 eclipse,所以在導入前需要先裝好 gradle 的插件金拒,直接在 help -> eclipse marketplace 里邊安裝
然后 file -> import -> gradle 選擇代碼目錄就好了兽肤,然后可能會出現(xiàn) spring-beans-groovy 這個模塊報錯,原因是因為沒有安裝 groovy 的編譯器導致的绪抛,同樣在 marketplace 中安裝
下載 spring 插件资铡, 在官網(wǎng) https://spring.io/tools/sts/all 中選擇eclipse 版本對應(yīng)的插件包
然后,help -> install new software 選擇下載好是 zip 文件
選 Spring IDE 相關(guān)
安裝完重啟后幢码,可以在 window -> show view -> other 中看到多了幾個