一只会飞的旺旺
文章92
标签72
分类8
Spring源码环境搭建

Spring源码环境搭建

小卖铺上新啦!ChatGPT账号大甩卖! 一键直达

环境准备

源码下载

github地址: https://github.com/spring-projects/spring-framework/tree/5.1.x

下载Spring源码,切换到5.1.X分支.

image-20220928203615450

gradle配置

1.通过源码中的地址,下载匹配版本的gradle

image-20220928203626356

2.配置gradle的环境变量

image-20220928203635545

3.在cmd中使用gradle -v命令,查看是否配置正确

4.修改IDEA中Gradle配置为本地配置

image-20220928203645744

5.修改Spring源码根目录的build.gradle文件,两处都添加阿里云maven仓库目录

repositories {
   maven { url 'https://maven.aliyun.com/repository/public/' }
   maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
   maven { url 'https://maven.aliyun.com/repository/apache-snapshots' }
   maven { url 'https://maven.aliyun.com/repository/central' }
   maven { url 'https://maven.aliyun.com/repository/google' }
   maven { url 'https://maven.aliyun.com/repository/jcenter' }
   maven { url 'https://maven.aliyun.com/repository/spring' }
   maven { url 'https://maven.aliyun.com/repository/spring-plugin' }
}

6.编译工程,顺序core-oxm-context-beans-aspects-aop, 点击tasks->compileTestJava

7.新建spring-model即可添加个人项目,开始源码阅读

常见问题

1.No such property: immutableValues for class: org.gradle.api.internal.tasks.DefaultTaskDependency

//修改spring-beans.gradle
注释掉这两行代码
//def deps = compileGroovy.taskDependencies.immutableValues + compileGroovy.taskDependencies.mutableValues
//compileGroovy.dependsOn = deps - 'compileJava'

2.Could not find method useJUnitPlatform()

注释:spring-test.gradle中这行代码
//  useJUnitPlatform {
//    includeEngines 'junit-jupiter'
//    excludeTags 'failing-test-case'
// }

3.错误如下

> Task :spring-beans:compileGroovy FAILED
D:\work_space\spring-framework\spring-beans\src\main\java\org\springframework\beans\support\PropertyComparator.java:138: 错误: 不兼容的类型: PropertyComparator<CAP
#1>无法转换为Comparator<? super CAP#1>
                        source.sort(new PropertyComparator<>(sortDefinition));

点击错误类,会直接跳转到该方法,然后直接返回值List泛型去掉

微信支付码 微信支付
支付宝支付码 支付宝支付