1

spring源代码下载

github上spring源代码地址:https://github.com/spring-pro...,直接从该项目上下载源代码

git clone https://github.com/spring-projects/spring-framework.git

这个地址下载是非常慢,有可能还会中途失败,这里告诉个小技巧,对于github上热门的项目,我们都可以在其镜像站中查找并下载:https://hub.fastgit.org

操作也非常简单,将上述命令中的(github.com替换为hub.fastgit.org),命令如下:

git clone https://hub.fastgit.org/spring-projects/spring-framework.git

切换分支

切换到release分支,根据需要切换到自己想学习的分支,本文是以5.2.x版本为例。

cd spring-framework
git checkout -b 5.2.x origin/5.2.x

环境准备

jdk8

gradle工具,下载地址:https://gradle.org/releases/

源代码导入idea

file -> open -> 找到下载的spring-framework目录下的build.gradle

注意:要对idea的工具进行如下设置

image.png

本文使用的grade-6.6.1版本,导入时,会出现如下报错:

Caused by: com.gradle.scan.plugin.BuildScanException: 
The build scan plugin is not compatible with Gradle 6.0 and later.
Please use the Gradle Enterprise plugin instead.
    at com.gradle.scan.plugin.BuildScanPlugin.a(SourceFile:99)

从报错中可以看到,是代码中的部分配置不支持Gradle6.0以上版本,在这里可以看到如何解决问题:https://docs.gradle.com/enter...

在settings.gradle中添加如下代码:

plugins {
 id "com.gradle.enterprise" version "3.5"
}

删除build.gradle中删除如下代码:

id 'com.gradle.build-scan' version '3.2'

再次reload gradle project,又会出现如下错误:

Caused by: groovy.lang.MissingPropertyException: 
Could not get unknown property 'variants' for object of type
org.gradle.api.plugins.internal.DefaultAdhocSoftwareComponent.

gradle/spring-moudle.gradle注释掉如下代码

// Once we upgrade to Gradle 6.x, we will need to delete the following line ...
// components.java.variants.removeAll { it.outgoingConfiguration.name.startsWith("testFixtures") }

再次 reload gradle project,根据网络情况,慢慢等待编译完成,首次编译要半小时的样子。

BUILD SUCCESSFUL

qinghua0310
0 声望0 粉丝