第一步:拉取Spring源码
下载地址:https://github.com/spring-projects/spring-framework
建议使用git clone 拉取,没有使用git拉取编译会报错如下:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 8m 55s
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:417)
at org.gradle.process.internal.DefaultExecAction.execute(DefaultExecAction.java:38)
at org.gradle.process.internal.DefaultExecActionFactory.exec(DefaultExecActionFactory.java:168)
at io.spring.ge.conventions.gradle.WorkingDirectoryProcessOperations.exec(WorkingDirectoryProcessOperations.java:45)
at io.spring.ge.conventions.gradle.ProcessOperationsProcessRunner.run(ProcessOperationsProcessRunner.java:41)
at io.spring.ge.conventions.core.BuildScanConventions.run(BuildScanConventions.java:166)
at io.spring.ge.conventions.core.BuildScanConventions.addGitMetadata(BuildScanConventions.java:113)
at io.spring.ge.conventions.gradle.GradleConfigurableBuildScan.lambda$background$0(GradleConfigurableBuildScan.java:104)
at com.gradle.enterprise.gradleplugin.internal.extension.b$3.run(SourceFile:101)
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:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
第二步:下载gradle并配置
2.1 下载gradle
下载地址:Gradle | Releases
gradle版本需要跟下载的Spring源码里gradle-wrapper.properties文件里的这个distributionUrl 值的版本号一致(如下图显示为5.6.4版本,根据自己相应的版本下载)。
第三步:修改相应的配置
3.1 修改spring源码的gradle-wrapper.properties配置文件
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
//将distributionUrl的值修改为下载到本地的gradle压缩包地址
//distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-bin.zip
distributionUrl=file\:///D:/software/Gradle/gradle-5.6.4-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl
修改为自己已下载的gradle压缩包本地地址,后面执行编译命令 会从D:\software\Gradle\gradle-5.6.4-bin.zip 下载gradle。
3.2 修改build.gradle文件(配置gradle远程仓库地址)
编译过程中会下载相应的依赖,默认的*仓库是国外的,不仅耗时还有可能下载失败的情况,添加阿里云镜像会快很多(感谢阿里爸爸)。
修改build.gradle 文件,添加阿里云的镜像(添加最下面两个)。
repositories {
mavenCentral()
maven { url "https://repo.spring.io/libs-spring-framework-build" }
maven { url "https://repo.spring.io/snapshot" } // reactor
//添加阿里云镜像
maven {url 'https://maven.aliyun.com/nexus/content/groups/public/'}
maven {url 'https://maven.aliyun.com/nexus/content/repositories/jcenter'}
}
3.3 修改settings.gradle文件(为了不做身份验证)
3.3.1 因版本而异,有得版本没有这个地方,没有跳过此步骤即可;
plugins {
id "com.gradle.enterprise" version "3.2"
// 注注释后,就不会再进行身份验证了
// id "io.spring.gradle-enterprise-conventions" version "0.0.2"
}
未使用ge.spring.io服务进行身份验证,执行会报错。
3.3.2 添加阿里镜像(与2.3步骤一样的作用)
repositories {
gradlePluginPortal()
maven { url 'https://repo.spring.io/plugins-release' }
//添加下面的阿里镜像
maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' }
maven { url 'https://maven.aliyun.com/nexus/content/repositories/jcenter' }
}
第三步:编译
3.1 将下载好的spring源码导入IDEA中,File >> Open 直接选择整个项目。
3.2 在IDEA中设置gradle的本地仓库地址;
然后点击编译,等待结果即可。
3.2 直接在idea控制台执行gradlew :spring-core:compileTestJava
3.3 编译好之后的效果如下
完结!!!
-----------------------------------------------这是底线------------------------------------------------