idea编译Spring5源码的完整过程

Posted 纵横千里,捭阖四方

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了idea编译Spring5源码的完整过程相关的知识,希望对你有一定的参考价值。

一直想编译一下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"

以上是关于idea编译Spring5源码的完整过程的主要内容,如果未能解决你的问题,请参考以下文章

使用idea社区版编译spring5源码

IDEA构造Spring5源码阅读环境

编译Spring5.2.0源码

深度解析Spring源码编译Spring源码(spring5.2.x版本)

用idea编译Spring源码错误问题记录

一步一步构建Spring5源码