spring源码构建,百分百成功,版本5.0.6

1. 安装gradle 4.9版本

下载地址:gradle4.9官网下载地址
百度云地址:https://pan.baidu.com/s/1HMDAhPg3y4JzP1mRX8IfrA
提取码: 1234

2. 设置gradle环境变量,编辑系统变量下的PATH变量

环境变量设置

3. 拉取spring 5.0.6源码

百度云网盘(推荐):https://pan.baidu.com/s/1UWn9JaEAuQOmi024myoILQ
提取码:1234
github地址:spring仓库地址

4.IDEA打开spring源码项目,修改IDEA配置

IDEA打开解压后的spring源码,打开项目后gradle会立即执行先点击停止按钮
依次点击IDEA File–》Settings–》Build,Execution,Deployment–》Build Tools–》Gradle,按照下图修改,指定的目录改为自己的目录即可
IDEA配置

5.修改工程根目录下build.gradle文件

直接使用如下文本替换所有内容

buildscript {
	repositories {
		maven { url "https://maven.aliyun.com/repository/spring-plugin" }
	}
	dependencies {
		classpath("io.spring.gradle:propdeps-plugin:0.0.8")
		classpath("io.spring.gradle:docbook-reference-plugin:0.3.1")
		classpath("org.asciidoctor:asciidoctorj-pdf:1.5.0-alpha.16")
		classpath("org.asciidoctor:asciidoctorj-epub3:1.5.0-alpha.7")
	}
}

// 3rd party plugin repositories can be configured in settings.gradle
plugins {
	id "com.gradle.build-scan" version "1.8"
	id "io.spring.dependency-management" version "1.0.3.RELEASE" apply false
	id "org.jetbrains.kotlin.jvm" version "1.2.41" apply false
	id "org.jetbrains.dokka" version "0.9.16"
	id "org.asciidoctor.convert" version "1.5.6"
}

buildScan {
	licenseAgreementUrl = 'https://gradle.com/terms-of-service'
	licenseAgree = 'yes'
}

ext {
	linkHomepage = 'https://projects.spring.io/spring-framework'
	linkCi = 'https://build.spring.io/browse/SPR'
	linkIssue = 'https://jira.spring.io/browse/SPR'
	linkScmUrl = 'https://github.com/spring-projects/spring-framework'
	linkScmConnection = 'scm:git:git://github.com/spring-projects/spring-framework.git'
	linkScmDevConnection = 'scm:git:ssh://git@github.com:spring-projects/spring-framework.git'

	moduleProjects = subprojects.findAll {
		!it.name.equals('spring-build-src') && !it.name.equals('spring-framework-bom')
	}
}

configure(allprojects) { project ->
	group = "org.springframework"
	version = qualifyVersionIfNecessary(version)

	ext.aspectjVersion       = "1.8.12"
	ext.freemarkerVersion    = "2.3.27-incubating"
	ext.groovyVersion        = "2.4.15"
	ext.hsqldbVersion        = "2.4.0"
	ext.jackson2Version      = "2.9.5"
	ext.jettyVersion         = "9.4.10.v20180503"
	ext.junitJupiterVersion  = "5.0.3"
	ext.junitPlatformVersion = "1.0.3"
	ext.junitVintageVersion  = "4.12.3"
	ext.kotlinVersion        = "1.2.41"
	ext.log4jVersion         = "2.11.0"
	ext.nettyVersion         = "4.1.24.Final"
	ext.reactorVersion       = "Bismuth-SR9"
	ext.rxjavaVersion        = "1.3.8"
	ext.rxjavaAdapterVersion = "1.2.1"
	ext.rxjava2Version       = "2.1.13"
	ext.slf4jVersion         = "1.7.25"	  // spring-jcl + consistent 3rd party deps
	ext.tiles3Version        = "3.0.8"
	ext.tomcatVersion        = "8.5.31"
	ext.undertowVersion      = "1.4.25.Final"

	ext.gradleScriptDir = "${rootProject.projectDir}/gradle"

	apply plugin: "propdeps"
	apply plugin: "java"
	apply plugin: "test-source-set-dependencies"
	apply from: "${gradleScriptDir}/ide.gradle"

	apply plugin: "kotlin"
	compileKotlin {
		kotlinOptions {
			jvmTarget = "1.8"
			freeCompilerArgs = ["-Xjsr305=strict"]
			apiVersion = "1.1"
			languageVersion = "1.1"
		}
	}
	compileTestKotlin {
		kotlinOptions {
			jvmTarget = "1.8"
			freeCompilerArgs = ["-Xjsr305=strict"]
		}
	}

	configurations.all {
		// Check for updates every build
		resolutionStrategy.cacheChangingModulesFor 0, 'seconds'

		// Consistent slf4j version (e.g. clashes between slf4j versions)
		resolutionStrategy.eachDependency { DependencyResolveDetails details ->
			if (details.requested.group == 'org.slf4j') {
				details.useVersion slf4jVersion
			}
		}

		exclude group: "org.slf4j", module: "jcl-over-slf4j"
	}

	def commonCompilerArgs =
			["-Xlint:serial", "-Xlint:cast", "-Xlint:classfile", "-Xlint:dep-ann",
			 "-Xlint:divzero", "-Xlint:empty", "-Xlint:finally", "-Xlint:overrides",
			 "-Xlint:path", "-Xlint:processing", "-Xlint:static", "-Xlint:try", "-Xlint:-options"]

	compileJava.options*.compilerArgs = commonCompilerArgs +
			["-Xlint:varargs", "-Xlint:fallthrough", "-Xlint:rawtypes",
			 "-Xlint:deprecation", "-Xlint:unchecked", "-Werror"]

	compileTestJava.options*.compilerArgs = commonCompilerArgs +
			["-Xlint:-varargs", "-Xlint:-fallthrough","-Xlint:-rawtypes",
			 "-Xlint:-deprecation", "-Xlint:-unchecked"]

	compileJava {
		sourceCompatibility = 1.8  // can be switched to 10 for testing
		targetCompatibility = 1.8
		options.encoding = 'UTF-8'
	}

	compileTestJava {
		sourceCompatibility = 1.8  // can be switched to 10 for testing
		targetCompatibility = 1.8
		options.encoding = 'UTF-8'
		options.compilerArgs += "-parameters"
	}

	test {
		systemProperty("java.awt.headless", "true")
		systemProperty("testGroups", project.properties.get("testGroups"))
		scanForTestClasses = false
		include(["**/*Tests.class", "**/*Test.class"])
		// Since we set scanForTestClasses to false, we need to filter out inner
		// classes with the "$" pattern; otherwise, using -Dtest.single=MyTests to
		// run MyTests by itself will fail if MyTests contains any inner classes.
		exclude(["**/Abstract*.class", '**/*$*'])
		reports.junitXml.setDestination(file("$buildDir/test-results"))
	}

	repositories {
		maven { url "http://maven.aliyun.com/nexus/content/groups/public" }
		maven { url "https://repo.spring.io/libs-release" }
	}

	dependencies {
		testCompile("junit:junit:4.12") {
			exclude group:'org.hamcrest', module:'hamcrest-core'
		}
		testCompile("org.mockito:mockito-core:2.12.0") {
			exclude group:'org.hamcrest', module:'hamcrest-core'
		}
		testCompile("com.nhaarman:mockito-kotlin:1.5.0") {
			exclude module:'kotlin-stdlib'
			exclude module:'kotlin-reflect'
			exclude module:'mockito-core'
		}
		testCompile("org.hamcrest:hamcrest-all:1.3")
		testRuntime("org.apache.logging.log4j:log4j-core:${log4jVersion}")
		testRuntime("org.apache.logging.log4j:log4j-slf4j-impl:${log4jVersion}")
		testRuntime("org.apache.logging.log4j:log4j-jul:${log4jVersion}")
		// JSR-305 only used for non-required meta-annotations
		compileOnly("com.google.code.findbugs:jsr305:3.0.2")
		testCompileOnly("com.google.code.findbugs:jsr305:3.0.2")
	}

	ext.javadocLinks = [
			"http://docs.oracle.com/javase/8/docs/api/",
			"http://docs.oracle.com/javaee/7/api/",
			"http://docs.oracle.com/cd/E13222_01/wls/docs90/javadocs/",  // CommonJ
			"http://pic.dhe.ibm.com/infocenter/wasinfo/v7r0/topic/com.ibm.websphere.javadoc.doc/web/apidocs/",
			"http://glassfish.java.net/nonav/docs/v3/api/",
			"http://docs.jboss.org/jbossas/javadoc/4.0.5/connector/",
			"http://docs.jboss.org/jbossas/javadoc/7.1.2.Final/",
			"http://tiles.apache.org/tiles-request/apidocs/",
			"http://tiles.apache.org/framework/apidocs/",
			"http://www.eclipse.org/aspectj/doc/released/aspectj5rt-api/",
			"http://ehcache.org/apidocs/2.10.4",
			"http://quartz-scheduler.org/api/2.2.1/",
			"http://fasterxml.github.io/jackson-core/javadoc/2.8/",
			"http://fasterxml.github.io/jackson-databind/javadoc/2.8/",
			"http://fasterxml.github.io/jackson-dataformat-xml/javadoc/2.8/",
			"http://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/"
	] as String[]
}

configure(subprojects - project(":spring-build-src")) { subproject ->
	apply from: "${gradleScriptDir}/publish-maven.gradle"

	jar {
		manifest.attributes["Implementation-Title"] = subproject.name
		manifest.attributes["Implementation-Version"] = subproject.version
		manifest.attributes["Automatic-Module-Name"] = subproject.name.replace('-', '.')  // for Jigsaw
		manifest.attributes["Created-By"] =
				"${System.getProperty("java.version")} (${System.getProperty("java.specification.vendor")})"

		from("${rootProject.projectDir}/src/docs/dist") {
			include "license.txt"
			include "notice.txt"
			into "META-INF"
			expand(copyright: new Date().format("yyyy"), version: project.version)
		}
	}

	javadoc {
		description = "Generates project-level javadoc for use in -javadoc jar"

		options.memberLevel = org.gradle.external.javadoc.JavadocMemberLevel.PROTECTED
		options.author = true
		options.header = project.name
		options.use = true
		options.links(project.ext.javadocLinks)
		options.addStringOption('Xdoclint:none', '-quiet')

		// Suppress warnings due to cross-module @see and @link references.
		// Note that global 'api' task does display all warnings.
		logging.captureStandardError LogLevel.INFO
		logging.captureStandardOutput LogLevel.INFO  // suppress "## warnings" message
	}

	task sourcesJar(type: Jar, dependsOn: classes) {
		duplicatesStrategy = DuplicatesStrategy.EXCLUDE
		classifier = 'sources'
		from sourceSets.main.allSource
		// Don't include or exclude anything explicitly by default. See SPR-12085.
	}

	task javadocJar(type: Jar) {
		classifier = "javadoc"
		from javadoc
	}

	artifacts {
//		archives sourcesJar
//		archives javadocJar
	}
}

configure(rootProject) {
	description = "Spring Framework"

	apply plugin: "groovy"
	apply plugin: "io.spring.dependency-management"
	apply from: "${gradleScriptDir}/jdiff.gradle"
	apply from: "${gradleScriptDir}/docs.gradle"

	dependencyManagement {
		imports {
			mavenBom "io.projectreactor:reactor-bom:${reactorVersion}"
		}
		resolutionStrategy {
			cacheChangingModulesFor 0, 'seconds'
		}
		applyMavenExclusions = false
	}

	// don't publish the default jar for the root project
	configurations.archives.artifacts.clear()

	dependencies {  // for integration tests
		testCompile(project(":spring-aop"))
		testCompile(project(":spring-beans"))
		testCompile(project(":spring-context"))
		testCompile(project(":spring-core"))
		testCompile(project(":spring-expression"))
		testCompile(project(":spring-jdbc"))
		testCompile(project(":spring-orm"))
		testCompile(project(":spring-test"))
		testCompile(project(":spring-tx"))
		testCompile(project(":spring-web"))
		testCompile("javax.inject:javax.inject:1")
		testCompile("javax.resource:javax.resource-api:1.7")
		testCompile("javax.servlet:javax.servlet-api:3.1.0")
		testCompile("org.aspectj:aspectjweaver:${aspectjVersion}")
		testCompile("org.hsqldb:hsqldb:${hsqldbVersion}")
		testCompile("org.hibernate:hibernate-core:5.1.13.Final")
	}

	artifacts {
//		archives docsZip
//		archives schemaZip
//		archives distZip
	}

	task wrapper(type: Wrapper) {
		description = "Generates gradlew[.bat] scripts"
		gradleVersion = '4.4.1'

		doLast() {
			def gradleOpts = "-XX:MaxMetaspaceSize=1024m -Xmx1024m"
			def gradleBatOpts = 	"$gradleOpts -XX:MaxHeapSize=256m"
			File wrapperFile = file("gradlew")
			wrapperFile.text = wrapperFile.text.replace("DEFAULT_JVM_OPTS=",
					"GRADLE_OPTS=\"$gradleOpts \$GRADLE_OPTS\"\nDEFAULT_JVM_OPTS=")
			File wrapperBatFile = file("gradlew.bat")
			wrapperBatFile.text = wrapperBatFile.text.replace("set DEFAULT_JVM_OPTS=",
					"set GRADLE_OPTS=$gradleBatOpts %GRADLE_OPTS%\nset DEFAULT_JVM_OPTS=")
		}
	}

}

/*
 * Support publication of artifacts versioned by topic branch.
 * CI builds supply `-P BRANCH_NAME=<TOPIC>` to gradle at build time.
 * If <TOPIC> starts with 'SPR-', change version
 *     from BUILD-SNAPSHOT => <TOPIC>-SNAPSHOT
 *     e.g. 3.2.1.BUILD-SNAPSHOT => 3.2.1.SPR-1234-SNAPSHOT
 */
def qualifyVersionIfNecessary(version) {
	if (rootProject.hasProperty("BRANCH_NAME")) {
		def qualifier = rootProject.getProperty("BRANCH_NAME")
		if (qualifier.startsWith("SPR-")) {
			return version.replace('BUILD', qualifier)
		}
	}
	return version
}

6. 修改spring-beans模块下的spring-beans.gradle

在这里插入图片描述
7. 快速构建,几分钟就能成功,使用阿里云仓库

重新构建

8.构建成功后续步骤

gradle objenesisRepackJar

gradle cglibRepackJar
执行命令

9. 执行测试 不必要
测试用例1个失败,无所谓
在这里插入图片描述

build.gradle改动地方:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
书籍链接:spring源码深度解析第二版
提取码:1234

编译有问题的话请留言评论

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值