源码编译踩坑

拉取源码

我这块以5.2.9版本为例

spring-projects/spring-framework at v5.2.9.RELEASE (github.com)

版本分析

在这里插入图片描述

确定版本

在这里插入图片描述

这块将Gradle升级到了5.6.4 ,我们去官网下载即可

Gradle安装

Gradle | Releases

在这里插入图片描述

解压

将其解压到你想存放的文件夹

配置环境变量

  • 右键“此电脑”–>“属性”–>“高级系统设置”–>“环境变量”–>“系统变量”
  • 我们在系统变量中新增一个GRADLE_HOME值为解压后的路径
  • 修改Path变量,将Gradle的bin目录添加进去,
  • 在Path变量添加%GRADLE_HOME%\bin

在环境变量中配置默认的仓库地址

在系统变量中新增一个GRADLE_USER_HOME 值为仓库路径

验证

默认下载依赖会在当前目录下

在这里插入图片描述

注释掉

安全导入 不信任

等配置结束后在信任文件

在这里插入图片描述

在这里插入图片描述

这些配置都看一下

在这里插入图片描述

修改版本
plugins {
	id 'io.spring.dependency-management' version '1.0.9.RELEASE' apply false
	//id 'io.spring.gradle-enterprise-conventions' version '0.0.2'
	id 'io.spring.nohttp' version '0.0.5.RELEASE'
	id 'org.jetbrains.kotlin.jvm' version '1.3.72' apply false
	id 'org.jetbrains.dokka' version '0.10.1' apply false
	id 'org.asciidoctor.jvm.convert' version '2.4.0'
	id 'de.undercouch.download' version '4.1.1'
	id "io.freefair.aspectj" version '4.1.6' apply false
	id 'com.gradle.build-scan' version '3.2'
	id "com.jfrog.artifactory" version '4.24.20' apply false
	id "com.github.ben-manes.versions" version '0.24.0'
}

因为spring是使用gradle打包的,我们在编译前先配置下gradle的国内镜像,找到项目里面的build.gradle文件,在repositories中添加代码保存,如下图

repositories {
			mavenCentral()
			maven { url "https://maven.aliyun.com/repository/public" }
			maven { url "https://maven.aliyun.com/repository/spring-plugin" }
			maven { url "https://maven.aliyun.com/nexus/content/groups/public/" }
			maven { url "https://maven.aliyun.com/nexus/content/repositories/spring-plugin" }
			maven { url 'http://maven.aliyun.com/nexus/content/repositories/google' }
			maven { url "https://repo.spring.io/libs-spring-framework-build" }
		}

gradle.properties

version=5.2.9.RELEASE
## 设置此参数主要是编译下载包会占用大量的内存,可能会内存溢出
org.gradle.jvmargs=-Xmx2048M
## 开启 Gradle 缓存
org.gradle.caching=true
## 开启并行编译
org.gradle.parallel=true
## 启用新的孵化模式
org.gradle.configureondemand=true
## 开启守护进程 通过开启守护进程,下一次构建的时候,将会连接这个守护进程进行构建,而不是重新fork一个gradle构建进程
org.gradle.daemon=true

等待构建

在这里插入图片描述

时间取决于网络

在这里插入图片描述

完成

测试

忒慢

在这里插入图片描述

给出build.gradle完整文件内容

plugins {
	id 'io.spring.dependency-management' version '1.0.9.RELEASE' apply false
	//id 'io.spring.gradle-enterprise-conventions' version '0.0.2'
	id 'io.spring.nohttp' version '0.0.5.RELEASE'
	id 'org.jetbrains.kotlin.jvm' version '1.3.72' apply false
	id 'org.jetbrains.dokka' version '0.10.1' apply false
	id 'org.asciidoctor.jvm.convert' version '2.4.0'
	id 'de.undercouch.download' version '4.1.1'
	id "io.freefair.aspectj" version '4.1.6' apply false
	id 'com.gradle.build-scan' version '3.2'
	id "com.jfrog.artifactory" version '4.24.20' apply false
	id "com.github.ben-manes.versions" version '0.24.0'
}

apply from: "$rootDir/gradle/build-scan-user-data.gradle"
ext {
	moduleProjects = subprojects.findAll { it.name.startsWith("spring-") }
	javaProjects = subprojects - project(":framework-bom")
	withoutJclOverSlf4j = {
		exclude group: "org.slf4j", name: "jcl-over-slf4j"
	}
}

configure(allprojects) { project ->
	apply plugin: "io.spring.dependency-management"

	dependencyManagement {
		imports {
			mavenBom "com.fasterxml.jackson:jackson-bom:2.10.5"
			mavenBom "io.netty:netty-bom:4.1.51.Final"
			mavenBom "io.projectreactor:reactor-bom:Dysprosium-SR12"
			mavenBom "io.rsocket:rsocket-bom:1.0.1"
			mavenBom "org.eclipse.jetty:jetty-bom:9.4.31.v20200723"
			mavenBom "org.jetbrains.kotlin:kotlin-bom:1.3.72"
			mavenBom "org.jetbrains.kotlinx:kotlinx-coroutines-bom:1.3.5"
			mavenBom "org.junit:junit-bom:5.6.2"
		}
		dependencies {
			dependencySet(group: 'org.apache.logging.log4j', version: '2.13.3') {
				entry 'log4j-api'
				entry 'log4j-core'
				entry 'log4j-slf4j-impl'
				entry 'log4j-jul'
			}
			dependency "org.slf4j:slf4j-api:1.7.30"
			dependency "com.google.code.findbugs:jsr305:3.0.2"

			dependencySet(group: 'org.aspectj', version: '1.9.6') {
				entry 'aspectjrt'
				entry 'aspectjtools'
				entry 'aspectjweaver'
			}
			dependencySet(group: 'org.codehaus.groovy', version: '2.5.13') {
				entry 'groovy'
				entry 'groovy-jsr223'
				entry 'groovy-templates'
				entry 'groovy-test'
				entry 'groovy-xml'
			}

			dependency "io.reactivex:rxjava:1.3.8"
			dependency "io.reactivex:rxjava-reactive-streams:1.2.1"
			dependency "io.reactivex.rxjava2:rxjava:2.2.19"
			dependency "io.projectreactor.tools:blockhound:1.0.2.RELEASE"

			dependency "com.caucho:hessian:4.0.63"
			dependency "com.fasterxml:aalto-xml:1.2.2"
			dependency("com.fasterxml.woodstox:woodstox-core:6.2.1") {
				exclude group: "stax", name: "stax-api"
			}
			dependency "com.google.code.gson:gson:2.8.6"
			dependency "com.google.protobuf:protobuf-java-util:3.11.4"
			dependency "com.googlecode.protobuf-java-format:protobuf-java-format:1.4"
			dependency("com.thoughtworks.xstream:xstream:1.4.11.1") {
				exclude group: "xpp3", name: "xpp3_min"
				exclude group: "xmlpull", name: "xmlpull"
			}
			dependency "org.apache.johnzon:johnzon-jsonb:1.2.8"
			dependency("org.codehaus.jettison:jettison:1.3.8") {
				exclude group: "stax", name: "stax-api"
			}
			dependencySet(group: 'org.jibx', version: '1.3.3') {
				entry 'jibx-bind'
				entry 'jibx-run'
			}
			dependency "org.ogce:xpp3:1.1.6"
			dependency "org.yaml:snakeyaml:1.26"

			dependency "com.h2database:h2:1.4.200"
			dependency "com.github.ben-manes.caffeine:caffeine:2.8.5"
			dependency "com.github.librepdf:openpdf:1.3.20"
			dependency "com.rometools:rome:1.12.2"
			dependency "commons-io:commons-io:2.5"
			dependency "io.vavr:vavr:0.10.3"
			dependency "net.sf.jopt-simple:jopt-simple:5.0.4"
			dependencySet(group: 'org.apache.activemq', version: '5.8.0') {
				entry 'activemq-broker'
				entry('activemq-kahadb-store') {
					exclude group: "org.springframework", name: "spring-context"
				}
				entry 'activemq-stomp'
			}
			dependency "org.apache.bcel:bcel:6.0"
			dependency "org.apache.commons:commons-pool2:2.8.0"
			dependencySet(group: 'org.apache.derby', version: '10.14.2.0') {
				entry 'derby'
				entry 'derbyclient'
			}
			dependency "org.apache.poi:poi-ooxml:4.1.2"
			dependency "org.apache-extras.beanshell:bsh:2.0b6"
			dependency "org.freemarker:freemarker:2.3.30"
			dependency "org.hsqldb:hsqldb:2.5.1"
			dependency "org.quartz-scheduler:quartz:2.3.2"
			dependency "org.codehaus.fabric3.api:commonj:1.1.0"
			dependency "net.sf.ehcache:ehcache:2.10.6"
			dependency "org.ehcache:jcache:1.0.1"
			dependency "org.ehcache:ehcache:3.4.0"
			dependency "org.hibernate:hibernate-core:5.4.21.Final"
			dependency "org.hibernate:hibernate-validator:6.1.5.Final"
			dependency "org.webjars:webjars-locator-core:0.45"
			dependency "org.webjars:underscorejs:1.8.3"

			dependencySet(group: 'org.apache.tomcat', version: '9.0.37') {
				entry 'tomcat-util'
				entry('tomcat-websocket') {
					exclude group: "org.apache.tomcat", name: "tomcat-websocket-api"
					exclude group: "org.apache.tomcat", name: "tomcat-servlet-api"
				}
			}
			dependencySet(group: 'org.apache.tomcat.embed', version: '9.0.37') {
				entry 'tomcat-embed-core'
				entry 'tomcat-embed-websocket'
			}
			dependencySet(group: 'io.undertow', version: '2.0.31.Final') {
				entry 'undertow-core'
				entry('undertow-websockets-jsr') {
					exclude group: "org.jboss.spec.javax.websocket", name: "jboss-websocket-api_1.1_spec"
				}
				entry('undertow-servlet') {
					exclude group: "org.jboss.spec.javax.servlet", name: "jboss-servlet-api_3.1_spec"
					exclude group: "org.jboss.spec.javax.annotation", name: "jboss-annotations-api_1.2_spec"
				}
			}

			dependencySet(group: 'com.squareup.okhttp3', version: '3.14.9') {
				entry 'okhttp'
				entry 'mockwebserver'
			}
			dependency("org.apache.httpcomponents:httpclient:4.5.12") {
				exclude group: "commons-logging", name: "commons-logging"
			}
			dependency("org.apache.httpcomponents:httpasyncclient:4.1.4") {
				exclude group: "commons-logging", name: "commons-logging"
			}
			dependency "org.eclipse.jetty:jetty-reactive-httpclient:1.1.4"

			dependency "org.jruby:jruby:9.2.11.1"
			dependency "org.python:jython-standalone:2.7.1"
			dependency "org.mozilla:rhino:1.7.11"

			dependency "commons-fileupload:commons-fileupload:1.4"
			dependency "org.synchronoss.cloud:nio-multipart-parser:1.1.0"

			dependency("dom4j:dom4j:1.6.1") {
				exclude group: "xml-apis", name: "xml-apis"
			}
			dependency("jaxen:jaxen:1.1.1") {
				exclude group: "xml-apis", name: "xml-apis"
				exclude group: "xom", name: "xom"
				exclude group: "xerces", name: "xercesImpl"
			}

			dependency("junit:junit:4.12") {
				exclude group: "org.hamcrest", name: "hamcrest-core"
			}
			dependency("de.bechte.junit:junit-hierarchicalcontextrunner:4.12.1") {
				exclude group: "junit", name: "junit"
			}
			dependency "org.testng:testng:6.14.3"
			dependency "org.hamcrest:hamcrest:2.1"
			dependency "org.awaitility:awaitility:3.1.6"
			dependency "org.assertj:assertj-core:3.17.2"
			dependencySet(group: 'org.xmlunit', version: '2.6.2') {
				entry 'xmlunit-assertj'
				entry('xmlunit-matchers') {
					exclude group: "org.hamcrest", name: "hamcrest-core"
				}
			}
			dependencySet(group: 'org.mockito', version: '3.3.3') {
				entry('mockito-core') {
					exclude group: "org.hamcrest", name: "hamcrest-core"
				}
				entry 'mockito-junit-jupiter'
			}
			dependency "io.mockk:mockk:1.10.0"

			dependency("net.sourceforge.htmlunit:htmlunit:2.43.0") {
				exclude group: "commons-logging", name: "commons-logging"
			}
			dependency("org.seleniumhq.selenium:htmlunit-driver:2.43.1") {
				exclude group: "commons-logging", name: "commons-logging"
			}
			dependency("org.seleniumhq.selenium:selenium-java:3.141.59") {
				exclude group: "commons-logging", name: "commons-logging"
				exclude group: "io.netty", name: "netty"
			}
			dependency "org.skyscreamer:jsonassert:1.5.0"
			dependency "com.jayway.jsonpath:json-path:2.4.0"

			dependencySet(group: 'org.apache.tiles', version: '3.0.8') {
				entry 'tiles-api'
				entry('tiles-core', withoutJclOverSlf4j)
				entry('tiles-servlet', withoutJclOverSlf4j)
				entry('tiles-jsp', withoutJclOverSlf4j)
				entry('tiles-el', withoutJclOverSlf4j)
				entry('tiles-extras') {
					exclude group: "org.springframework", name: "spring-web"
					exclude group: "org.slf4j", name: "jcl-over-slf4j"
				}
			}
			dependency("org.apache.taglibs:taglibs-standard-jstlel:1.2.5") {
				exclude group: "org.apache.taglibs", name: "taglibs-standard-spec"
			}

			dependency "com.ibm.websphere:uow:6.0.2.17"
			dependency "com.jamonapi:jamon:2.82"
			dependency "joda-time:joda-time:2.10.6"
			dependency "org.eclipse.persistence:org.eclipse.persistence.jpa:2.7.7"
			dependency "org.javamoney:moneta:1.3"

			dependency "com.sun.activation:javax.activation:1.2.0"
			dependency "com.sun.mail:javax.mail:1.6.2"
			dependencySet(group: 'com.sun.xml.bind', version: '2.3.0.1') {
				entry 'jaxb-core'
				entry 'jaxb-impl'
				entry 'jaxb-xjc'
			}

			dependency "javax.activation:javax.activation-api:1.2.0"
			dependency "javax.annotation:javax.annotation-api:1.3.2"
			dependency "javax.cache:cache-api:1.1.0"
			dependency "javax.ejb:javax.ejb-api:3.2"
			dependency "javax.el:javax.el-api:3.0.1-b04"
			dependency "javax.enterprise.concurrent:javax.enterprise.concurrent-api:1.0"
			dependency "javax.faces:javax.faces-api:2.2"
			dependency "javax.inject:javax.inject:1"
			dependency "javax.inject:javax.inject-tck:1"
			dependency "javax.interceptor:javax.interceptor-api:1.2.2"
			dependency "javax.jms:javax.jms-api:2.0.1"
			dependency "javax.json:javax.json-api:1.1.4"
			dependency "javax.json.bind:javax.json.bind-api:1.0"
			dependency "javax.mail:javax.mail-api:1.6.2"
			dependency "javax.money:money-api:1.0.3"
			dependency "javax.resource:javax.resource-api:1.7.1"
			dependency "javax.servlet:javax.servlet-api:4.0.1"
			dependency "javax.servlet.jsp:javax.servlet.jsp-api:2.3.2-b02"
			dependency "javax.servlet.jsp.jstl:javax.servlet.jsp.jstl-api:1.2.1"
			dependency "javax.transaction:javax.transaction-api:1.3"
			dependency "javax.validation:validation-api:2.0.1.Final"
			dependency "javax.websocket:javax.websocket-api:1.1"
			dependency "javax.xml.bind:jaxb-api:2.3.1"
			dependency "javax.xml.ws:jaxws-api:2.3.1"

			dependency "org.eclipse.persistence:javax.persistence:2.2.0"

			// Substitute for "javax.management:jmxremote_optional:1.0.1_04" which
			// is not available on Maven Central
			dependency "org.glassfish.external:opendmk_jmxremote_optional_jar:1.0-b01-ea"
			dependency "org.glassfish:javax.el:3.0.1-b08"
			dependency "org.glassfish.main:javax.jws:4.0-b33"
			dependency "org.glassfish.tyrus:tyrus-container-servlet:1.13.1"
		}
		generatedPomCustomization {
			enabled = false
		}
		resolutionStrategy {
			cacheChangingModulesFor 0, "seconds"
		}
		repositories {
			mavenCentral()
			maven { url "https://maven.aliyun.com/repository/public" }
			maven { url "https://maven.aliyun.com/repository/spring-plugin" }
			maven { url "https://maven.aliyun.com/nexus/content/groups/public/" }
			maven { url "https://maven.aliyun.com/nexus/content/repositories/spring-plugin" }
			maven { url 'http://maven.aliyun.com/nexus/content/repositories/google' }
			maven { url "https://repo.spring.io/libs-spring-framework-build" }
		}
	}
	configurations.all {
		resolutionStrategy {
			cacheChangingModulesFor 0, "seconds"
			cacheDynamicVersionsFor 0, "seconds"
		}
	}
}

configure([rootProject] + javaProjects) { project ->
	group = "org.springframework"

	apply plugin: "java"
	apply plugin: "java-test-fixtures"
	apply plugin: "checkstyle"
	apply plugin: 'org.springframework.build.compile'
	apply from: "${rootDir}/gradle/custom-java-home.gradle"
	apply from: "${rootDir}/gradle/ide.gradle"

	pluginManager.withPlugin("kotlin") {
		apply plugin: "org.jetbrains.dokka"
		compileKotlin {
			kotlinOptions {
				jvmTarget = "1.8"
				freeCompilerArgs = ["-Xjsr305=strict"]
				allWarningsAsErrors = true
			}
		}
		compileTestKotlin {
			kotlinOptions {
				jvmTarget = "1.8"
				freeCompilerArgs = ["-Xjsr305=strict"]
			}
		}
	}

	test {
		useJUnitPlatform()
		include(["**/*Tests.class", "**/*Test.class"])
		systemProperty("java.awt.headless", "true")
		systemProperty("testGroups", project.properties.get("testGroups"))
		systemProperty("io.netty.leakDetection.level", "paranoid")
	}

	checkstyle {
		toolVersion = "8.36.1"
		configDir = rootProject.file("src/checkstyle")
	}

	dependencies {
		testCompile("org.junit.jupiter:junit-jupiter-api")
		testCompile("org.junit.jupiter:junit-jupiter-params")
		testCompile("org.mockito:mockito-core")
		testCompile("org.mockito:mockito-junit-jupiter")
		testCompile("io.mockk:mockk")
		testCompile("org.assertj:assertj-core")
		// Pull in the latest JUnit 5 Launcher API to ensure proper support in IDEs.
		testRuntime("org.junit.platform:junit-platform-launcher")
		testRuntime("org.junit.jupiter:junit-jupiter-engine")
		testRuntime("org.apache.logging.log4j:log4j-core")
		testRuntime("org.apache.logging.log4j:log4j-slf4j-impl")
		testRuntime("org.apache.logging.log4j:log4j-jul")
		// JSR-305 only used for non-required meta-annotations
		compileOnly("com.google.code.findbugs:jsr305")
		testCompileOnly("com.google.code.findbugs:jsr305")
		checkstyle("io.spring.javaformat:spring-javaformat-checkstyle:0.0.15")
	}

	ext.javadocLinks = [
			"https://docs.oracle.com/javase/8/docs/api/",
			"https://docs.oracle.com/javaee/7/api/",
			"https://docs.oracle.com/cd/E13222_01/wls/docs90/javadocs/",  // CommonJ
			"https://www.ibm.com/support/knowledgecenter/SS7JFU_8.5.5/com.ibm.websphere.javadoc.doc/web/apidocs/",
			"https://glassfish.java.net/nonav/docs/v3/api/",
			"https://docs.jboss.org/jbossas/javadoc/4.0.5/connector/",
			"https://docs.jboss.org/jbossas/javadoc/7.1.2.Final/",
			"https://tiles.apache.org/tiles-request/apidocs/",
			"https://tiles.apache.org/framework/apidocs/",
			"https://www.eclipse.org/aspectj/doc/released/aspectj5rt-api/",
			"https://www.ehcache.org/apidocs/2.10.4/",
			"https://www.quartz-scheduler.org/api/2.3.0/",
			"https://fasterxml.github.io/jackson-core/javadoc/2.10/",
			"https://fasterxml.github.io/jackson-databind/javadoc/2.10/",
			"https://fasterxml.github.io/jackson-dataformat-xml/javadoc/2.10/",
			"https://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/",
			"https://junit.org/junit4/javadoc/4.12/",
			"https://junit.org/junit5/docs/5.6.2/api/"
	] as String[]
}

configure(moduleProjects) { project ->
	apply from: "${rootDir}/gradle/spring-module.gradle"
}

configure(rootProject) {
	description = "Spring Framework"

	apply plugin: "groovy"
	apply plugin: "kotlin"
	apply plugin: "io.spring.nohttp"
	apply plugin: 'org.springframework.build.api-diff'
	apply from: "${rootDir}/gradle/publications.gradle"
	apply from: "${rootDir}/gradle/docs.gradle"

	nohttp {
		source.exclude "**/test-output/**"
		allowlistFile = project.file("src/nohttp/allowlist.lines")
		def rootPath = file(rootDir).toPath()
		def projectDirs = allprojects.collect { it.projectDir } + "${rootDir}/buildSrc"
		projectDirs.forEach { dir ->
			[ 'bin', 'build', 'out', '.settings' ]
				.collect { rootPath.relativize(new File(dir, it).toPath()) }
				.forEach { source.exclude "$it/**" }
			[ '.classpath', '.project' ]
				.collect { rootPath.relativize(new File(dir, it).toPath()) }
				.forEach { source.exclude "$it" }
		}
	}

	publishing {
		publications {
			mavenJava(MavenPublication) {
				artifact docsZip
				artifact schemaZip
				artifact distZip
			}
		}
	}
}

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部