1. 程式人生 > 其它 >springboot原始碼學習1 springboot2.3.4原始碼編譯

springboot原始碼學習1 springboot2.3.4原始碼編譯

一 下載原始碼

方式1 碼雲下載


碼雲是國內的倉庫,極速下載是github上面的知名專案映象,可以快速下載,找到內容後,點選main切換分支,找到自己想看的分支

方式二:github下載

不管是什麼方式下載,建議下release版本,避免去踩一些不必要的坑,解決坑是一個體力活很費時費力,本次我下載的是2.3.4版本

二 下載gradle



下載下來zip就可以了

三 修改配置檔案編譯

修改配置檔案主要是修改映象源和一些踩到的編譯坑:

1 gradle\wrapper中的配置檔案

將檔案內容 修改成自己的目錄,就是上面下載的zip gradle目錄就可以了

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=file:///D:/java/gradle-6.6.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

2 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
.......`

3 buildSrc下的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}"
}
}
}
}`

4 buildSrc下的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`

5 根目錄下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"
}

}`

6 根目錄下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}" } } } }

7編譯