这两天想着把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));
}
}
输出成功