准备:
spring-framework5.0,可通过码云下载(https://gitee.com/mirrors/Spring-Framework?_from=gitee_search),选择相应的分支,码云国内下载快
jdk1.8.0_202
gradle5.5.1
开发工具:idea
下载的spring-framework解压后,文件夹下import-into-idea.md,是详细的导入idea过程。
一、编译,进入spring-framework目录,cmd,执行
gradlew :spring-oxm:compileTestJava
二、导入项目
打开IDEA,File->New->Project From Existing Source…,选中Spring-framework文件夹,选中Gradle,点击Next,然后点击Finish,等待IDEA导入即可。
三、改错吧
1、gradle版本问题,使用5.5.1
exception during working with external system: java.lang.AssertionError
修改gradle-wrapper.properties文件,我的gradle是5.5.1
distributionUrl=https://services.gradle.org/distributions/gradle-5.5.1-all.zip
2、com.gradle.build-scan 版本
Build file 'D:\work\git\Spring-Framework\build.gradle' line: 16
An exception occurred applying plugin request [id: 'com.gradle.build-scan', version: '1.8']
Failed to apply plugin [id 'com.gradle.build-scan']
This version of Gradle requires version 2.0.2 of the build scan plugin or later.
Please see https://gradle.com/scans/help/gradle-incompatible-plugin-version for more information.
修改:version 2.0.2
3、licenseAgreementUrl 许可协议吧,注释吧
Build file 'D:\work\git\Spring-Framework\build.gradle' line: 24
A problem occurred evaluating root project 'spring'.
Could not set unknown property 'licenseAgreementUrl' for com.gradle.scan.plugin.internal.api.g@60155566 of type com.gradle.scan.plugin.internal.api.h_Decorated.
修改:
buildScan {
// licenseAgreementUrl = "https://gradle.com/terms-of-service"
// licenseAgree = "yes"
publishAlways()
}
4、task wrapper(type: Wrapper) 语法变了
Build file 'D:\work\git\Spring-Framework\build.gradle' line: 296
A problem occurred evaluating root project 'spring'.
Cannot add task 'wrapper' as a task with that name already exists.
修改:
task wrapper(type: Wrapper) {
}
为:
wrapper{
}
5、注释属性 values for class: org.gradle.api.internal.tasks.DefaultTaskDependency Possible solutions: values
Build file 'D:\work\git\Spring-Framework\spring-beans\spring-beans.gradle' line: 29
A problem occurred evaluating project ':spring-beans'.
No such property: values for class: org.gradle.api.internal.tasks.DefaultTaskDependency Possible solutions: values
修改:
注释掉 compileGroovy.dependsOn = compileGroovy.taskDependencies.values - "compileJava"
6、成功
Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.5.1/userguide/command_line_interface.html#sec:command_line_warnings
CONFIGURE SUCCESSFUL in 8s
CONFIGURE SUCCESSFUL in 256ms
四、总结:
通过码云下载的spring源码包:mirrors-Spring-Framework-5.0.x.zip
查看java版本
C:\Users\wind>java -version
java version "1.8.0_202"
Java(TM) SE Runtime Environment (build 1.8.0_202-b08)
Java HotSpot(TM) 64-Bit Server VM (build 25.202-b08, mixed mode)
查看gradle版本
C:\Users\wind>gradle -version
Welcome to Gradle 5.5.1!
Here are the highlights of this release:
- Kickstart Gradle plugin development with gradle init
- Distribute organization-wide Gradle properties in custom Gradle distributions
- Transform dependency artifacts on resolution
For more details see https://docs.gradle.org/5.5.1/release-notes.html
------------------------------------------------------------
Gradle 5.5.1
------------------------------------------------------------
Build time: 2019-07-10 20:38:12 UTC
Revision: 3245f748c7061472da4dc184991919810f7935a5
Kotlin: 1.3.31
Groovy: 2.5.4
Ant: Apache Ant(TM) version 1.9.14 compiled on March 12 2019
JVM: 1.8.0_202 (Oracle Corporation 25.202-b08)
OS: Windows 10 10.0 amd64