idea编译Spring5源码的完整过程

本文详细介绍了在Mac系统上,使用IntelliJ IDEA 2019版本,配合JVM 1.8,如何成功编译Spring 5.0.2源码的过程。主要步骤包括修改build.gradle的repositories,更新gradle-wrapper.properties中的本地路径,注释docs.gradle中导致编译失败的部分,以及解决aspectj和dokka版本问题。通过这些步骤,可以避免编译过程中出现的常见错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一直想编译一下Spring5源码,这样更方便研究,但是一直卡壳,今天彻底梳理完整个过程:

 

环境:mac10.15.7,idea版本2019,JVM1.8,Spring5.0.2。

目前spring已经出5.3甚至更高版本了,但是要依赖JDK17,我不想搞两个JDK,所以安装Spring5.0.2版本就够了,高级特性以后再说。

下载之后可以直接导入到idea中,此时idea会自动开始编译,但是十有八九会因为错误而终止,此时配置可以参考这个文件:

IDEA搭建Spring-Framework-5.3源码阅读环境 - 灰信网(软件开发博客聚合)

下面将我遇到的一些坑补充进来

一.修改build.gradle里的repositories:

	repositories {
		mavenLocal()
		maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' }
		maven { url 'https://maven.aliyun.com/nexus/content/repositories/spring-plugin' }
	}

二.修改文件gradle-wrapper.properties,将两个path改成本地的路径,这样可以防止每次编译都重新下载gradle。

distributionUrl=https\://services.gradle.org/distributions/gradle-4.3.1-bin.zip
distributionBase=GRADLE_USER_HOME
distributionPath=/Users/***/Desktop/soft/wrapper/dists
zipStorePath=/Users/****/Desktop/soft/wrapper/dists
zipStoreBase=GRADLE_USER_HOME

三.之后再打开docs.gradle,将下面的内容注释掉,这个是生成文档的,但是构建的时候会失败,干脆注释掉了:

//dokka {
//	dependsOn {
//		subprojects.collect {
//			it.tasks.getByName("jar")
//		}
//	}
//	doFirst {
//		classpath = subprojects.collect { project -> project.jar.outputs.files.getFiles() }.flatten()
//		classpath += files(subprojects.collect { it.sourceSets.main.compileClasspath })
//
//	}
//	moduleName = "spring-framework"
//	outputFormat = "html"
//	outputDirectory = "$buildDir/docs/kdoc"
//
//	sourceDirs = files(subprojects.collect { project ->
//		project.sourceSets.main.kotlin.srcDirs
//	})
//	externalDocumentationLink {
//		url = new URL("http://docs.spring.io/spring-framework/docs/${version}/javadoc-api/")
//	}
//	externalDocumentationLink {
//		url = new URL("http://projectreactor.io/docs/core/release/api/")
//	}
//	externalDocumentationLink {
//		url = new URL("http://www.reactive-streams.org/reactive-streams-1.0.1-javadoc/")
//	}
//}

//asciidoctor {
//	sources {
//		include '*.adoc'
//	}
//	resources {
//		from(sourceDir) {
//			include 'images/*', 'stylesheets/*', 'tocbot-3.0.2/*'
//		}
//	}
//	logDocuments = true
//	backends = ["html5"]
//	// only ouput PDF documentation for non-SNAPSHOT builds
//	if(!project.getVersion().toString().contains("BUILD-SNAPSHOT")) {
//		backends += "pdf"
//	}
//	options doctype: 'book', eruby: 'erubis'
//	attributes  'icons': 'font',
//			'idprefix': '',
//			'idseparator': '-',
//			docinfo: '',
//			revnumber: project.version,
//			sectanchors: '',
//			sectnums: '',
//			'source-highlighter': 'coderay@', // TODO switch to 'rouge' once supported by the html5 backend
//			stylesdir: 'stylesheets/',
//			stylesheet: 'main.css',
//			'spring-version': project.version
//
//}

四.之后打开spring-aspects.gradle文件,这里默认用的是1.9.0-RC2,但是貌似这个版本并不存在,我们选择一个最接近的1.9.1l来替换。

ajc("org.aspectj:aspectjtools:1.9.1")  // for JDK 9 build compatibility
	rt("org.aspectj:aspectjrt:1.9.1")  // for JDK 9 build compatibility

五.Could not resolve org.jetbrains.dokka:integration:0.9.15 错误现象,修改build.gradle文件

将id "org.jetbrains.dokka" version "0.9.15" 修改为

id "org.jetbrains.dokka" version "0.9.17"

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

纵横千里,捭阖四方

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

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

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

打赏作者

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

抵扣说明:

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

余额充值