Gradle编译Spring的源码(超详细)

Gradle编译Spring的源码

1、下载安装插件

下载安装gradle和spring5的源码包,并且配置好gradle的环境、

2、导入项目
选择项目的gradle文件进行导入:
在这里插入图片描述
配置好自动导包和本地的gradle
在这里插入图片描述

点击确定之后,会进入编译,一定会报错,我们拭目以待!
错误一:提示spring-beans.gradle错误。解决方案:直接注释掉该句话。如图所示。
在这里插入图片描述
在这里插入图片描述
这里会进行大量的jar的下载,请耐心等待。
编译完成后,对oxm和beans和context进行依次的编译。compileTestJava
在这里插入图片描述

错误二:提示beans模块出现循环依赖
在这里插入图片描述

解决方案:在spring-beans.gradle后面加这样几句代码:

def deps = compileGroovy.taskDependencies.immutableValues + compileGroovy.taskDependencies.mutableValues
compileGroovy.dependsOn = deps - "compileJava"
compileKotlin.dependsOn(compileGroovy)
compileKotlin.classpath += files(compileGroovy.destinationDir)

效果图如下图;
在这里插入图片描述

我们继续进行编译、初次编译时间可能会较长,请耐心等待。(三个模块都需要按顺序进行编译)

编译完成我们可以创建项目(gradle项目)了:
项目创建完成之后添加spring-context的依赖;

dependencies {
    compile(project(":spring-context"))
    testCompile group: 'junit', name: 'junit', version: '4.12'
}

这时候我们写代码进行测试:

@Configuration
public class MainConfig {
   
}
public class MainTest {

   public static void main(String[] args) {
      AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MainConfig.class);
      System.out.println(context);
   }
}

点击运行!
错误三:显示找不到instrument包
在这里插入图片描述

解决方案:在我们自己的模块中添加spring-instrument包的依赖:

compile(project(":spring-instrument"))

最终的依赖:

dependencies {
    compile(project(":spring-context"))
    compile(project(":spring-instrument"))
    testCompile group: 'junit', name: 'junit', version: '4.12'
}

再次运行代码:成功!!

到此为止,gradle编译spring源码结束!

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

吴涛_1618

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值