Spring源码

2023-12-20 20:14:51

1.源码下载

本文编译的Spring源码是v5.2.x版本,jdk1.8 ,gradle6.5.1 仅供参考。

用gitee从github上导入spring的源码,然后从gitee上下载源码

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

在这里插入图片描述
然后就可以从gitee上面Clone到本地

2.gradle下载以及安装(或者使用idea自带的,这步跳过)

  1. 下载Gradle前,先到Spring源码目录 ,进入到:spring-framework-5.2.x\gradle\wrapper 查看gradle-wrapper.properties 文件,下图中,distributionUrl对应的则为当前Spring源码版本对应的Gradle版本。 (本次本人使用的是gradle6.5.1,也报错)
    ![gradle]在这里插入图片描述
  1. 配置Gradle下载地址: https://gradle.org/releases/
    配置Gradle环境变量一:
    变量名:GRADLE_USER
    变量值:D:\software\gradle-6.5.1 (这里是我本地的gradle路径)
    配置Gradle环境变量二:
    变量名:GRADLE_USER_HOME
    变量值:D:\gradle-repo (这里配置的是gradle的仓库地址)
    配置Gradle环境变量三,配置 Path:
    环境变量值:%GRADLE_USER%\bin

在这里插入图片描述

  1. 校验
    在这里插入图片描述

3.修改源码配置

  1. 找到源码根目录 build.gradle 文件 (相当于maven的pom),找到repositories配置向,编辑修改镜像仓库配置
    在这里插入图片描述
repositories {
			maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' }
			maven { url 'https://maven.aliyun.com/nexus/content/repositories/jcenter'}
			mavenCentral()
			maven { url "https://repo.spring.io/libs-spring-framework-build" }
		}

2.找到源码根目录 settings.gradle 文件增加国内镜像
在这里插入图片描述

pluginManagement {
	repositories {
		maven { url 'https://maven.aliyun.com/repository/public' }
		maven { url 'https://repo.spring.io/plugins-release' }
		mavenCentral()
		gradlePluginPortal()
		maven { url "https://repo.spring.io/release" }
	}
}

4.源码编译

1.将项目导入idea
2.修改idea中gradle配置
在这里插入图片描述
注释 :

  1. Gradle user home 仓库地址,我给配置成了gradle安装地址,导致包下载到了安装目录,然后懒得改了
  2. Use Gradle from 默认是项目使用的gradle,有由我安装的gradle跟spring默认需要的gradle版本不一致,导致编译报错,所以使用的默认的,参考:spring-framework-5.2.x\gradle\wrapper 查看gradle-wrapper.properties 文件

5.编译问题

配置完毕后,开始build项目,Gradle开始下载一些相关文件,下载完毕后会出现以下信息:

Starting Gradle Daemon...

Gradle Daemon started in 2 s 826 ms

fatal: not a git repository (or any of the parent directories): .git

> Task :buildSrc:compileJava UP-TO-DATE

> Task :buildSrc:compileGroovy NO-SOURCE

> Task :buildSrc:pluginDescriptors UP-TO-DATE

> Task :buildSrc:processResources UP-TO-DATE

> Task :buildSrc:classes UP-TO-DATE

> Task :buildSrc:jar UP-TO-DATE

> Task :buildSrc:generateSourceRoots UP-TO-DATE

> Task :buildSrc:assemble UP-TO-DATE

> Task :buildSrc:pluginUnderTestMetadata UP-TO-DATE

> Task :buildSrc:compileTestJava NO-SOURCE

> Task :buildSrc:compileTestGroovy NO-SOURCE

> Task :buildSrc:processTestResources NO-SOURCE

> Task :buildSrc:testClasses UP-TO-DATE

> Task :buildSrc:test SKIPPED

> Task :buildSrc:validatePlugins UP-TO-DATE

> Task :buildSrc:check SKIPPED

> Task :buildSrc:build UP-TO-DATE

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

See Command-Line Interface

BUILD SUCCESSFUL in 13m 13s

7 actionable tasks: 7 up-to-date

A build scan was not published as you have not authenticated with server 'ge.spring.io'.

For more information, please see https://gradle.com/help/gradle-authenticating-with-gradle-enterprise.

Build scan background action failed.

org.gradle.process.internal.ExecException: Process 'command 'git'' finished with non-zero exit value 128

at org.gradle.process.internal.DefaultExecHandle$ExecResultImpl.assertNormalExitValue(DefaultExecHandle.java:415)

at org.gradle.process.internal.DefaultExecAction.execute(DefaultExecAction.java:38)

at org.gradle.process.internal.DefaultExecActionFactory.exec(DefaultExecActionFactory.java:202)

at io.spring.ge.conventions.gradle.WorkingDirectoryProcessOperations.exec(WorkingDirectoryProcessOperations.java:45)

at io.spring.ge.conventions.gradle.ProcessOperationsProcessRunner.run(ProcessOperationsProcessRunner.java:40)

at io.spring.ge.conventions.gradle.BuildScanConventions.run(BuildScanConventions.java:195)

at io.spring.ge.conventions.gradle.BuildScanConventions.addGitMetadata(BuildScanConventions.java:139)

at com.gradle.enterprise.gradleplugin.internal.extension.a$4.run(SourceFile:172)

at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)

at java.util.concurrent.FutureTask.run(FutureTask.java:266)

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)

at java.lang.Thread.run(Thread.java:745)

BUILD SUCCESSFUL in 2m 7s


解决Git报错

1.进入spring源码根目录下,打开终端执行以下命令

1. git init .
2. git add .
3. git commit -am '初始化提交'

2.提交完重新刷新构建

参考 :

参考1
参考2

文章来源:https://blog.csdn.net/chen1092248901/article/details/135106563
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。