Spring Framework 5.3.x源码构建 (jdk-1.8, gradle 7.5.1, idea2024.3)
1、下载jdk安装并配置环境变量(自行百度)
https://www.oracle.com/java/technologies/downloads/#java8
2、下载spring-framework源码,切换分支到5.3.x
https://github.com/spring-projects/spring-framework.git
备用地址
https://gitcode.com/gh_mirrors/sp/spring-framework
3、下载gradle 7.5.1, 配置环境变量(自行百度)
https://mirrors.aliyun.com/gradle/distributions/v7.5.1/
4、配置IDEA
ctrl + alt + s 打开设置
配置IDEA的本地gradle环境
配置项目字节码版本
ctrl + alt + shift + s 打开项目结构
5、配置 gradle/wrapper/gradle-wrapper.properties 文件参数
5.1配置gradle下载地址为本地(路径为gradle二进制文件压缩包路径)
distributionUrl=file:///D:/gradle/gradle-7.5.1-bin.zip
配置仓库镜像
根目录下文件\buildSrc\build.gradle
repositories {maven { url 'https://maven.aliyun.com/repository/public/' }maven { url 'https://maven.aliyun.com/repository/central' }mavenCentral()gradlePluginPortal()
}
根目录下文件\build.gradle
mavenCentral() 之前加上
maven { url 'https://maven.aliyun.com/repository/public/' }maven { url 'https://maven.aliyun.com/repository/central' }maven { url "https://maven.aliyun.com/repository/spring-plugin" }maven { url "https://maven.aliyun.com/repository/gradle-plugin" }
6、新建模块,测试环境
添加依赖 /spring-f2-test/build.gradle
添加测试类
package com.lister;
public class User {String name;public User(String name) {this.name = name;}public String getName() {return name;}public void setName(String name) {this.name = name;}@Overridepublic String toString() {return "User{" +"name='" + name + '\'' +'}';}
}
package com.lister;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class JavaConfig {@Beanpublic User user(){return new User("lister");}
}
package com.lister;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
public class MainApplication {public static void main(String[] args) {AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(JavaConfig.class);User user = (User) context.getBean("user");System.out.println(user);}
}
运行MainApplication的main方法输出信息如下
测试spring-framework项目本地源码构建完成