Spring源码编译踩坑记录

这两天想着把spring源码整一下,于是开始艰辛的编译spring源码
首先从git上拉下来,这人人都会
安装gradle(在下以前只用过Maven)

然后就出了一系列问题…艰苦奋斗一番之后贴上我的运行环境供大家参考

首先IDEA版本是2020.1,不知道为什么2019.3.3始终有问题无法导入项目,无奈之下升级了2020.1,之前就知道2020.1挺香的,只是之前太懒了没升级
在这里插入图片描述
之后是能编译了,不过Gradle下载jar包真的超慢的,加国内镜像是快很多
注意,此时repository有两个!
第三行这里不用改
在这里插入图片描述
加在149行这里
在这里插入图片描述
加了之后在Gradle configure build阶段会快很多,大概会快…从4小时变成10分钟吧?

下载完依赖的jar之后会indexing,用不了多久
之后sidebar gradle项目可以展开就导入成功了
在这里插入图片描述
之后开始编译,首先编译spring-core,因为之后的spring-context依赖于core
在这里插入图片描述
编译完之后把gradle的运行环境改一下
在这里插入图片描述
之后运行一下项目中的Test
在这里插入图片描述
接着运行spring-context中的Test
在这里插入图片描述
这时候应该就没问题了,整个gradle的module测试一下
build.gradle

plugins {
    id 'java'
}

group 'org.springframework'
version '5.1.15.BUILD-SNAPSHOT'

repositories {
    maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
    maven{ url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'}
    mavenCentral()
    maven { url "https://repo.spring.io/libs-release" }
    maven { url "https://repo.spring.io/snapshot" }
    maven { url "https://repo.spring.io/plugins-release" }
}

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

TestDao

package com.ky;

import org.springframework.stereotype.Repository;

@Repository
public class TestDao {
}

JavaConfig

package com.ky;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration
@ComponentScan("com.ky")
public class JavaConfig {
}

Test

package com.ky;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class Test {

	public static void main(String[] args) {
		AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext(JavaConfig.class);
		System.out.println(ac.getBean(TestDao.class));
	}
}

输出成功
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值