本文基于以下版本验证:
项目版本下载地址SpringBoot2.0.4releasehttps://github.com/spring-projects/spring-bootSpringFramework5.0.8.releasehttps://github.com/spring-projects/spring-framework为什么要编译源码?Spring的源码,注释非常清晰,能够帮助读者理解框架中接口和类的作用,对理解Spring框架非常重要。 由于SpringBoot的源码,采用maven框架,编译比较简单,这里不介绍。重点介绍下SpringFramework源码的编译过程。
如果下载不下来,可以使用我在码云上提交的版本:https://gitee.com/muziye/spring-framework-5.0.8.git
发现使用的是gradle4.4.1
安装idea一般默认已经安装了gradle。注意版本对应: gradle 4.4.1 的执行程序在 C:\Users\Administrator.gradle\wrapper\dists\gradle-4.4.1-bin\46gopw3g8i1v3zqqx4q949t2x\gradle-4.4.1\bin 建系统环境变量 GRADLE_HOME=C:\Users\Administrator.gradle\wrapper\dists\gradle-4.4.1-bin\46gopw3g8i1v3zqqx4q949t2x\gradle-4.4.1 然后在系统环境变量 Path 的最后添加上 ;%GRADLE_HOME%\bin 注意 别漏了符号 ; 具体操作过程 和添加 JAVA_HOME的过程一样 简略过程如下: win7 电脑 -》计算机 -》右键属性 -》 环境变量 -》 高级系统设置 -》 环境变量 -》新建系统变量:GRADLE_HOME值为C:\Users\Administrator.gradle\wrapper\dists\gradle-4.4.1-bin\46gopw3g8i1v3zqqx4q949t2x\gradle-4.4.1 -》编辑系统变量Path 在最后面 增加;%GRADLE_HOME%\bin
打开spring-beans.gradle,注释掉一下代码:
// This module also builds Kotlin code and the compileKotlin task // naturally depends on compileJava. // We need to redefine dependencies to break task cycles. //compileGroovy.dependsOn = compileGroovy.taskDependencies.values - 'compileJava' //def deps = compileGroovy.taskDependencies.immutableValues + compileGroovy.taskDependencies.mutableValues //compileGroovy.dependsOn = deps - 'compileJava' //compileKotlin.dependsOn(compileGroovy) //compileKotlin.classpath += files(compileGroovy.destinationDir)如果整体编译的话,由于缺少部分引用,源码还会报错。不影响阅读,这里就跳过了。