1.准备环境
1.1 下载spring源码
下载spring源码。通过idea直接打开,如果有build直接关掉build,因为在没改配置前,build会失败
1.2 gradle版本选择
打开文件gradle-wrapper.properties,可以查看spring版本需要的gradle版本

1.3 安装gradle
下载对应的gradle版本,并安装,安装教程很多,本文不在描述,本文spring版本对应的gradle版本为Gradle 4.3.1
2.改maven仓库,构建spring
在根目录下找到build.gradle文件,全局搜下这个configurations.all,把整个都注释掉然后加上阿里云的库,不然你打完王者都还没结束
// configurations.all {
// // Check for updates every build
// resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
// }
allprojects {
repositories {
maven{ url 'http://maven.aliyun.com/nexus/content/groups/public'}
}
}

保存好,build下,等几分钟就好了
完整的build.gradle文件
buildscript {
repositories {
maven { url "https://repo.spring.io/plugins-release" }
}
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.1.61" apply false
id "org.jetbrains.dokka" version "0.9.17"
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.13"
ext.freemarkerVersion = "2.3.27-incubating"
ext.groovyVersion = "2.4.13"
ext.hsqldbVersion = "2.4.0"
ext.jackson2Version = "2.9.2"
ext.jettyVersion = "9.4.7.v20170914"
ext.junitJupiterVersion = "5.0.2"
ext.junitPlatformVersion = "1.0.2"
ext.junitVintageVersion = "4.12.2"
ext.kotlinVersion = "1.1.61"
ext.log4jVersion = "2.10.0"
ext.nettyVersion = "4.1.17.Final"
ext.reactorVersion = "Bismuth-SR4"
ext.rxjavaVersion = "1.3.4"
ext.rxjavaAdapterVersion = "1.2.1"
ext.rxjava2Version = "2.1.6"
ext.slf4jVersion = "1.7.25"
ext.tiles3Version = "3.0.8"
ext.tomcatVersion = "8.5.23"
ext.undertowVersion = "1.4.21.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"
kotlinOptions.freeCompilerArgs = ["-Xskip-runtime-version-check", "-Xjsr305=strict"]
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
kotlinOptions.freeCompilerArgs = ["-Xskip-runtime-version-check", "-Xjsr305=strict"]
}
// configurations.all {
// // Check for updates every build
// resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
// }
allprojects {
repositories {
maven{ url 'http://maven.aliyun.com/nexus/content/groups/public'}
}
}
def commonCompilerArgs =
["-Xlint:serial", "-Xlint:cast", "-Xlint:classfile", "-Xlint:dep-ann",
"-Xlint:divzero", "-Xlin

本文介绍了如何使用gradle构建spring源码。首先,详细讲解了从下载spring源码到选择合适的gradle版本,以及安装gradle的过程。接着,重点讲述了修改maven仓库为阿里云库以加速构建。最后,指导如何在spring源码中新增module并进行测试,以确保构建成功。

3690

被折叠的 条评论
为什么被折叠?



