本文使用的IDEA为社区版本。源码编译地址(自行拉取到本地或fork到自己的git仓库):https://github.com/Nuclear-Core-Learning/spring-framework
IDEA下载地址:https://www.jetbrains.com/idea/download/other.html
目录
前言
先决条件
Gradle下载
Gradle解压
配置环境变量
测试安装
编译之前
导入IDEA
IDEA Spring源码构建
JDK8以后版本依赖
已安装JDK/JRE(版本7或以上),这里是Win10系统
在命令行输入:java -version 可查询当前电脑已安装的版本
从 Gralde 官方网站下载 Gradle 的最新发行包。
Gradle 发行包是一个 ZIP 文件。完整的发行包包括以下内容(官方发行包有 full 完整版,也有不带源码和文档的版本,可根据需求下载。[Rover12421]译注):
运行 gradle 必须将 GRADLE_HOME/bin 加入到你的 PATH 环境变量中。
运行如下命令来检查是否安装成功.该命令会显示当前的 JVM 版本和 Gradle 版本。
gradle -v
JVM 参数配置
Gradle 运行时的 JVM 参数可以通过 GRADLE_OPTS 或 JAVA_OPTS 来设置.这些参数将会同时生效。 JAVA_OPTS 设置的参数将会同其它 JAVA 应用共享,一个典型的例子是可以在 JAVA_OPTS 中设置代理和 GRADLE_OPTS 设置内存参数。同时这些参数也可以在 gradle 或者 gradlew 脚本文件的开头进行设置。
1、cd 进入spring-framework代码目录
2、修改sesstings.gradle 设置阿里云仓库地址
pluginManagement {
repositories {
gradlePluginPortal()
maven { url 'https://maven.aliyun.com/repository/public' }
maven { url 'https://repo.spring.io/plugins-release' }
}
}
3、修改build.gradle依然添加阿里云仓库地址
repositories {
maven { url 'https://maven.aliyun.com/nexus/content/groups/public' }
maven { url 'https://maven.aliyun.com/nexus/content/repositories/jcenter' }
mavenCentral()
maven { url "https://repo.spring.io/libs-spring-framework-build" }
}
4、修改gradle.properties,调大JVM参数
version=5.3.3-SNAPSHOT
org.gradle.jvmargs=-Xmx2048M
org.gradle.caching=true
org.gradle.parallel=true
kotlin.stdlib.default.dependency=false
5、编译spring-oxm
1、选择存在的项目资源导入
2、选择spring-framework源码目录
3、选择Gradle项目
4、导入项目参数配置
2018.3.4 https://youtrack.jetbrains.com/issue/IDEA-207327?_ga=2.262020813.155240518.1608166853-1295022405.1581304547
更多:https://www.jetbrains.com/idea/download/other.html
注意:看发布日志,有些修复了Gradle的问题。
gradle-wrapper.properties, 指定gradle的工具包为6.1
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Download https://services.gradle.org/distributions/gradle-6.1-bin.zip (97.47 MB)
Download https://services.gradle.org/distributions/gradle-6.1-bin.zip finished succeeded, took 1 m 52 s 622 ms
Starting Gradle Daemon...
Gradle Daemon started in 6 s 517 ms
> Task :buildSrc:compileJava
> Task :buildSrc:compileJava UP-TO-DATE
> Task :buildSrc:compileGroovy NO-SOURCE
> Task :buildSrc:pluginDescriptors UP-TO-DATE
> Task :buildSrc:processResources UP-TO-DATE
> Task :buildSrc:classes UP-TO-DATE
> Task :buildSrc:jar UP-TO-DATE
> Task :buildSrc:assemble UP-TO-DATE
> Task :buildSrc:pluginUnderTestMetadata
> Task :buildSrc:compileTestJava NO-SOURCE
> Task :buildSrc:compileTestGroovy NO-SOURCE
> Task :buildSrc:processTestResources NO-SOURCE
> Task :buildSrc:testClasses UP-TO-DATE
> Task :buildSrc:test NO-SOURCE
> Task :buildSrc:validatePlugins UP-TO-DATE
> Task :buildSrc:check UP-TO-DATE
> Task :buildSrc:build UP-TO-DATE
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.1/userguide/command_line_interface.html#sec:command_line_warnings
CONFIGURE SUCCESSFUL in 8m 52s
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.1/userguide/command_line_interface.html#sec:command_line_warnings
CONFIGURE SUCCESSFUL in 8m 46s
注意:出现java.lang.NoClassDefFoundError: org/gradle/api/internal/plugins/DefaultConvention 就表示Idea和Gradle版本不兼容。
spring-core
最新JDK下载地址:https://www.oracle.com/cn/java/technologies/javase-downloads.html
账号:[email protected]
密码:Oracle123
下载11LTS稳定长期维护版本:
问题解决!