javascript
IntelliJ IDEA导入Spring源码
工欲善其事,必先利其器,研究spring源碼,從導入源碼開始吧。本文記錄自己 Windows下 IDEA 導入源碼折騰的過程。
內(nèi)容說明:
本文內(nèi)容同微信公眾號【凡登】,歡迎關注共同學習。
spring源碼構建參見 官方文檔?https://github.com/spring-projects/spring-framework/wiki/Build-from-Source
1、下載spring源碼
安裝git,Spring源碼現(xiàn)在在github托管,spring官網(wǎng)找到github小圖標,點擊進入,復制spring源碼地址,使用git下載,
spring源碼 git地址https://github.com/spring-projects/spring-framework.git
圖示:
2、下載gradle、安裝配置gradle環(huán)境變量
To build you will need?Git?and?JDK 8 update 60 or later. Be sure that your?JAVA_HOME?environment variable points to the?jdk1.8.0?folder extracted from the JDK download.
安裝前確保javahome在jdk1.8.0.60以上版本,
2.1、找到合適gradle版本
windows解壓zip包,打開spring-framework-5.0.x\gradle\wrapper\gradle-wrapper.properties查看源碼使用的gradle的版本號
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4.1-bin.zip
2.2、下載安裝gradle,??
gradle下載地址,安裝配置gradle環(huán)境變量,?使用gradle -v測試是否安裝成功
查看是否安裝成功
3、編譯spring源碼
3.1、解壓spring源碼包,進入當前目錄,shift + 鼠標右鍵選擇(在此處打開命令窗口) ,鍵入 gradlew build 開始構建,
加速構建,可在源碼包根目錄build.gradle中更新如下配置參考地址,可加快構建效率
repositories {maven { url 'http://maven.aliyun.com/nexus/content/repositories/google' }maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' } maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'}maven { url 'http://repo.springsource.org/plugins-release'} }新增以下配置(沒有以下配置,構建過程超級慢……),定義全局的國內(nèi)鏡像,注意該配置不能在plugins { }之前
allprojects {repositories {maven { url 'http://maven.aliyun.com/nexus/content/repositories/google' }maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'}maven { url 'http://repo.springsource.org/plugins-release'}} }項目第一次構建,加載相關依賴包,比較慢,構建過程中會出現(xiàn)Read timed out ,提示構建失敗,只需再次構建即可
3.2、將spring jar安裝到本地maven倉庫? 命令:gradlew install -x javadoc
-x javadoc跳過文檔
4、導入源碼到intell idea
4.1、打開IDEA,File->New->Project From Existing Sources
4.2、選擇下載的本地spring源碼
4.3、配置gradle 操作,配置后點擊OK開始導入,過程有點長,如果配置國內(nèi)鏡(參考3.1)像會好很多,
5、配置jdk1.8, spring高版本中使用了1.8新特性,為了避免報錯,需要配置
5.1、File--->Setting
5.2、File--->>Project Structure
6、開始spring源碼旅行
?7、可能出現(xiàn)的問題
7.1、gradle版本與scan版本問題
異常1: An exception occurred applying plugin request [id: 'com.gradle.build-scan', version: '1.8'] > Failed to apply plugin [id 'com.gradle.build-scan']> This version of Gradle requires version 2.0.2 of the build scan plugin or later.Please see https://gradle.com/scans/help/gradle-incompatible-plugin-version for more information.異常2:No such property: values for class: org.gradle.api.internal.tasks.DefaultTaskDependency解決:參考Gradle Enterprise version compatibility | Gradle Enterprise Docs?找到合適的版本,并在gradle.properties中替換如:
plugins {id "com.gradle.build-scan" version "1.8" // 替換版本號id "io.spring.dependency-management" version "1.0.7.RELEASE" apply falseid "org.jetbrains.kotlin.jvm" version "1.2.71" apply falseid "org.jetbrains.dokka" version "0.9.18"id "org.asciidoctor.convert" version "1.5.6" }7.2、導入已經(jīng)編譯后的spring源碼到idea中,出現(xiàn)異常
idea 內(nèi)置的gradle版本過低,沒有與源碼中對應的gradle版本,降低源碼中的gradle.properties中的班
Error:No such property: GradleVersion for class: JetGradlePlugin解決方法:參考2.1
7.3、導入源碼到idea中,出現(xiàn)jar下載不到,下載超時
Error:Could not find io.spring.gradle:propdeps-plugin:0.0.9.RELEASE. Searched in the following locations:https://plugins.gradle.org/m2/io/spring/gradle/propdeps-plugin/0.0.9.RELEASE/propdeps-plugin-0.0.9.RELEASE.pomhttps://plugins.gradle.org/m2/io/spring/gradle/propdeps-plugin/0.0.9.RELEASE/propdeps-plugin-0.0.9.RELEASE.jarhttp://maven.aliyun.com/nexus/content/repositories/google/io/spring/gradle/propdeps-plugin/0.0.9.RELEASE/propdeps-plugin-0.0.9.RELEASE.pomhttp://maven.aliyun.com/nexus/content/repositories/google/io/spring/gradle/propdeps-plugin/0.0.9.RELEASE/propdeps-plugin-0.0.9.RELEASE.jarhttp://maven.aliyun.com/nexus/content/groups/public/io/spring/gradle/propdeps-plugin/0.0.9.RELEASE/propdeps-plugin-0.0.9.RELEASE.pomhttp://maven.aliyun.com/nexus/content/groups/public/io/spring/gradle/propdeps-plugin/0.0.9.RELEASE/propdeps-plugin-0.0.9.RELEASE.jarhttp://maven.aliyun.com/nexus/content/repositories/jcenter/io/spring/gradle/propdeps-plugin/0.0.9.RELEASE/propdeps-plugin-0.0.9.RELEASE.pomhttp://maven.aliyun.com/nexus/content/repositories/jcenter/io/spring/gradle/propdeps-plugin/0.0.9.RELEASE/propdeps-plugin-0.0.9.RELEASE.jar Required by:project :解決:參考3.1
總結(jié)
以上是生活随笔為你收集整理的IntelliJ IDEA导入Spring源码的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 有限元笔记04:二维实体单元
- 下一篇: while中的break