Spring-boot 2.3.x源码基于Gradle编译过程详解

spring Boot源码编译

1. git上下拉最新版的spring Boot

下载:git clone git@github.com:spring-projects/spring-boot.git,建议下载release版本,不会出现奇奇怪怪的错误

2.修改下载源,

gradle\wrapper中的配置文件

gradle-wrapper.properties

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
#distributionUrl=https\://services.gradle.org/distributions/gradle-6.4-bin.zip
//这里Gradle换成你自己存放gradle的路径以及gradle的压缩包名
//这里需要注意的是gradle版本问题,尽量高一点儿,就是用了gradle-4.9的版本,导致报错gradle-api plugins问题,还缺包啥的,换了包之后就没问题了
distributionUrl=file:///E:/Gitee_repository/Java_Sources_Code_Study/Spring-Boot-2.3.1/gradle-6.5.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

buildSrc下的build.gradle

plugins {
	id "java-gradle-plugin"
	//可能是原有的编译环境,注释掉,否则报错
	//id "io.spring.javaformat" version "${javaFormatVersion}"
	id "checkstyle"
}

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

sourceCompatibility = 1.8
targetCompatibility = 1.8
.......

settings.gradle

pluginManagement {
	repositories {
		maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' }
		maven { url 'https://maven.aliyun.com/nexus/content/repositories/jcenter' }
		maven { url "https://repo.spring.io/plugins-release" }
		mavenCentral()
		gradlePluginPortal()
	}
	resolutionStrategy {
		eachPlugin {
			if (requested.id.id == "io.spring.javaformat") {
				useModule "io.spring.javaformat:spring-javaformat-gradle-plugin:${requested.version}"
			}
		}
	}
}

gradle.properties

javaFormatVersion=0.0.22
#新增如下配置,解决heap堆内存空间不够问题
gradlePropertiesProp=gradlePropertiesValue
sysProp=shouldBeOverWrittenBySysProp
systemProp.system=systemValue
org.gradle.caching=false
org.gradle.jvmargs=-Xms2048m -Xmx4096m 
org.gradle.parallel=true
org.gradle.daemon=true
org.gradle.configureondemand=true

根目录下的build.gradle

// 放在第一行
buildscript {
	repositories {
		maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' }
		maven { url 'https://maven.aliyun.com/nexus/content/repositories/jcenter' }
		maven { url "https://repo.spring.io/plugins-release" }
	}
}

allprojects {
	group "org.springframework.boot"

	repositories {
		maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' }
		maven { url 'https://maven.aliyun.com/nexus/content/repositories/jcenter' }
		mavenCentral()
		if (!version.endsWith('RELEASE')) {
			maven { url "https://repo.spring.io/milestone" }
		}
		if (version.endsWith('BUILD-SNAPSHOT')) {
			maven { url "https://repo.spring.io/snapshot" }
		}
	}

	configurations.all {
		resolutionStrategy.cacheChangingModulesFor 60, "minutes"
	}
}

seetings.gradle

pluginManagement {
	repositories {
		maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' }
		maven { url 'https://maven.aliyun.com/nexus/content/repositories/jcenter' }
		mavenCentral()
		gradlePluginPortal()
		maven {
			url 'https://repo.spring.io/plugins-release'
		}
		if (version.endsWith('BUILD-SNAPSHOT')) {
			maven { url "https://repo.spring.io/snapshot" }
		}
	}
	resolutionStrategy {
		eachPlugin {
			if (requested.id.id == "org.jetbrains.kotlin.jvm") {
				useVersion "${kotlinVersion}"
			}
			if (requested.id.id == "org.jetbrains.kotlin.plugin.spring") {
				useVersion "${kotlinVersion}"
			}
		}
	}
}

2. idea导入

在编译的时候点击取消,配置idea


3.开始编译

至此撒花编译成功!

不过后面还有好长时间的检测,不知道是什么鬼??

到此这篇关于Spring-boot 2.3.x源码基于Gradle编译过程详解的文章就介绍到这了,更多相关Spring-boot 2.3.x源码内容请搜索呐喊教程以前的文章或继续浏览下面的相关文章希望大家以后多多支持呐喊教程!

声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:notice#nhooo.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。