Win10 + IDEA2019.3 搭建Spring5.1.x 源碼開發環境


本機環境:

  • Win10 家庭版64位
  • IDEA 2019.3.1
  • Spring 5.1.x
  • Gradle 5.6.4
  • Git 2.20.1

0、編譯環境初始化

如上所述的環境都安裝好,配置好環境變量:
GRADLE_HOME:
在這里插入圖片描述
GRADLE_USER_HOME:
在這里插入圖片描述
然后在CMD查看Gradle的版本如下即表示配置成功:
在這里插入圖片描述

1、下載Spring源碼

我是用git clone 碼雲的這個鏡像下來后,切換到5.1.x 分支。

2、編譯-導入源碼

Spring-framework的源碼目錄有個導入IDEA的說明文檔:import-into-idea.md,內容如下:

_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

1、我們cmd進入這個根目錄,然后先編譯spring-oxm這個工程,因為其它spring組件會依賴這個。
2、IDEA里面導入這個根目錄工程:
在這里插入圖片描述
選擇Spring-framework目錄后,選擇導入方式為Gradle,然后點擊finish:
在這里插入圖片描述

3、然后點擊File -- Project Structure 進去 modules里面排除 Spring-aspect 目錄:
在這里插入圖片描述

5、然后,修改Gradle配置文件,修改版本為 5.6.4:
D:\Study\Spring-framework-5.1.x-gitee\Spring-Framework\gradle\wrapper\gradle-wrapper.properties

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=file\:/D:/DevEnv/gradle-5.6.4-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

distributionUrl 這個參數的值改為指向你本地的下載的 5.6.4 的zip包路徑

同時修改Cache.properties 里面的Gradle為對應的版本:
D:\Study\Spring-framework-5.1.x-gitee\Spring-Framework.gradle\buildOutputCleanup\cache.properties
在這里插入圖片描述
然后,在IDEA里面配置Gradle為你自己的版本:
在這里插入圖片描述

最后,在IDEA里面打開一個終端Terminate,輸入命令進行編譯即可:
在這里插入圖片描述

編譯完成后,IDEA會自動建立工程的資源索引,然后展開工程目錄,所有的Spring組件包的目錄,左側的文件夾圖標都是有右下角那個藍色標識的,才標識編譯完成
在這里插入圖片描述

如果出現編譯時Spring-tx 這個模塊無法編譯通過,提示找不到這個IBM的jar包:

Could not find com.ibm.websphere:uow:6.0.2.17.
Searched in the following locations:
  - file:/C:/Users/Administrator/.m2/repository/com/ibm/websphere/uow/6.0.2.17/uow-6.0.2.17.pom
  - file:/C:/Users/Administrator/.m2/repository/com/ibm/websphere/uow/6.0.2.17/uow-6.0.2.17.jar
  - https://maven.aliyun.com/repository/public/com/ibm/websphere/uow/6.0.2.17/uow-6.0.2.17.pom
  - https://maven.aliyun.com/repository/public/com/ibm/websphere/uow/6.0.2.17/uow-6.0.2.17.jar
  - http://nexus.bsdn.org/content/groups/public/com/ibm/websphere/uow/6.0.2.17/uow-6.0.2.17.pom
  - http://nexus.bsdn.org/content/groups/public/com/ibm/websphere/uow/6.0.2.17/uow-6.0.2.17.jar
  - https://repo.maven.apache.org/maven2/com/ibm/websphere/uow/6.0.2.17/uow-6.0.2.17.pom
  - https://repo.maven.apache.org/maven2/com/ibm/websphere/uow/6.0.2.17/uow-6.0.2.17.jar
Required by:
    project :spring-tx

在這里插入圖片描述

解決辦法是需要自己到mavenrepo上下載jar手動install到自己本地的maven倉庫:

mvn install:install-file -Dfile=uow-6.0.2.17.jar -DgroupId=com.ibm.websphere -DartifactId=uow -Dversion=6.0.2.17 -Dpackaging=jar

然后重新編譯即可。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM