1. 程式人生 > 程式設計 >Spring-boot 2.3.x原始碼基於Gradle編譯過程詳解

Spring-boot 2.3.x原始碼基於Gradle編譯過程詳解

spring Boot原始碼編譯

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

下載:git clone [email protected]: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原始碼內容請搜尋我們以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援我們!