1 Spring 5 源码下载

首先你的 JDK 需要升级到 1.8 以上版本。从 Spring 3.0 开始, Spring 源码采用 GitHub 托管,不再提供官网下载链接。这里不做过多赘述,大家可自行去 GitHub 网站下载,我使用的版本下载链接为 https://github.com/spring-projects/spring-framework/archive/v5.0.2.RELEASE.zip ,下载完成后,解压源码包会看到如下图所示的文件目录。

2 基于 Gradle 的源码构建技巧

由于从 Spirng 5 开始都采用 Gradle 编译,所以构建源码前需要先安装 Gradle 。 Gradle 下载地址为 https://gradle.org/releases ,我使用的是 Spring 5 官方推荐的版本 Gradle 4.0 ,下载链接为 https://gradle.org/next-steps/?version=4.0&format=bin ,下载完成后按以下步骤操作,这里以 Windows 操作系统为例。

第一步,配置环境变量,如下图所示。

第二步,添加环境变量 “ %GRADLE_HOME%\bin ”,如下图所示。

第三步,检测环境,输入 gradle -v 命令,得到如下图所示结果。

----------------------------------------------------------------------Gradle 4.0---------------------------------------------------------------------- Build time:2017-06-14 15:11:08 UTCRevision: 316546a5fcb4e2dfe1d6aaÜb73a4e09e8cecb5a5 Groovy:2. 4. 11Ant:Apache Ant THD version 1. 9.6 compiled on June 29 2015JVM:1.8.0_ 131 (Oracle Corporation 25.131-b11)OS:Windows 10 10. 0 amd64

第四步,编译源码,将 cmd 切到 spring-framework-5.0.2.RELEASE 目录,运行 gradlew.bat ,如下图所示。

Starting a Gradle Daemon (subeequent builds wi11 be faster)

 > Task :he1p We1come to Gradle 4.3.1. To run a build, run gradlew <task> ... To see a list of available tasks, run gradlew tasks To see a list of command-line options, run gradlew –help To see more detail about a task, run gradlew help --task <task> DUILD SUCCESSPUL in 8s1 actionable task: 1 executed

第五步,转换为 E clipse 项目,执行 import-into-eclipse.bat 命令,构建前请确保网络状态良好,按任意键继续:

----------------------------------------------------------------------Spring Framework - Eclipse/STS project impart guide This script will guide you through the process of importing the SpringFramerork projects into Ec1ipse or the Spring Tool Suite STS) It isrecommended that you have a recent version of Eclipse or STS. As a bareminimum you wi11 need Eclipse with full Java 8 support, the AspectJDevelopment Tools (AJDT), and the Groovy Compiler. If you need to download and install Eclipse or STS, please do that nowby visiting one of the following sites: - Eclipse dommloads: http://dowload.eclipse.org/eclipse/dowloads- STS dowmloads: http://spring.io/too1s/sts/a11- STS nightly builds:http://dist.springsource.com/snapshot/STS/night1y-distributions.html- ADJT: http://www.eclipse.org/ajdt/downloads/- Groovy Eclipse: https://github.com/groovy/groovy-eclipse/wiki Otheryise. prgss enter and we’11 begin.

请按任意键继续 . . .

----------------------------------------------------------------------

STEP 1: Generate subproject Eclipse metadata The first step wil1 be to generate Eclipse project metadata for eachof the spring-* subprojects. This happens via the built-in"Gradle wrapper" script (./gradlew in this directory). If this is yourfirst time using the Gradle wrapper, this step may take a fewr minuteswhile a Gradle distribution is downloaded for you.

第六步,等待构建成功(若中途出现错误,大部分情况是由于网络中断造成的,一般重试一下都能解决问题),构建成功后会出现如下信息:

BUILD SUOCESSFUL in 6s6 actionable tasks: 6 executed ----------------------------------------------------------------------STEP 4: Import root project into Ec1ipse/STS Follow the project inport steps listed in step 2 above to inport theroot project. Press. enter, when complete, and move on to the final step.请按任意键继续. . . ----------------------------------------------------------------------STEP 5: Enable Git support for all projects - In the Ec1ipse/STS Package Exp1orer, se1ect al1 spring* projects.- Right-click to cpen the context menu and select Team > Share Project...- In the Share Project dialog that appears, select Git and press Next- Check "Use or create repository in parent folder of project"- C1ick Finish When complete, you' 11 have Git support enabled for all projects. You' re ready to code! Goodbye!

到此为止,已经可以将项目导入 Eclipse 了。我们推荐使用的 IDEA 也比较智能,可以直接兼容 Eclipse 项目。接下来继续看下面的步骤。

第七步,导入 IDEA 。打开 IntelliJ IDEA ,单击“ Import Project ”,在弹出的界面中选择 spring-framework-5.0.2.RELEASE 文件夹,单击“ OK ”按钮,再单击“ F inish ”按钮,如下三图所示。

第八步,等待构建完成,在网络良好的情况下大约需要 10 分钟便可自动构建完成,你会看到如下图所示界面。

第九步,在 IDEA 中,如果能找到 ApplicationContext 类,按 Ctrl+Shift+Alt+U 键,出现如下图所示类图界面说明构建成功。

3 Gradle 构建过程中的坑

如果项目环境一直无法构建成功,类图无法自动生成,那么你一定是踩到了一个坑。

第一步,单击 View → Tool Windows → Gradle 命令,如下图所示。

第二步,单击 Gradle 视图中的刷新按钮,如下图所示。

这时会出现如下图所示的错误。

第三步,出现错误显然跟 Gradle 没有任何关系,解决办法:

( 1 )关闭 IDEA ,打开任务管理器,结束跟 J ava 有关的所有进程。

( 2 )找到 JAVA_HOME → jre → lib 目录,将 tools.jar 重命名为 tools.jar.bak 。

( 3 )重启 IDEA ,再次单击刷新按钮,等待构建完成。

4 小测一下

本文分享自微信公众号 - Tom弹架构(gh_e3be84a8ccb2)。
如有侵权,请联系 support@oschina.cn 删除。
本文参与“  OSC源创计划  ”,欢迎正在阅读的你也加入,一起分享。

Spring源码下载及构建技巧相关推荐

  1. spring源码下载编译

    环境准备 spring源码 下载地址: Git->https://github.com/spring-projects/spring-framework.git gitee->https: ...

  2. Spring源码下载与编译

    文章目录 环境准备 Spring源码下载 导入IDEA 测试 环境准备 安装jdk,idea,maven并做好相应配置 操作系统:windows Spring源码下载 Spring源码Github仓库 ...

  3. Spring源码下载与编译,Debug学习才有效率

    这里写自定义目录标题 一.源码下载 1.github源码下载 2.阅读项目编译文档 2.1.项目编译 (1).解压我们下载好的目录 (2).配置阿里云镜像 (3).编译 (4).遇到的坑 2.2.导入 ...

  4. 1.Gradle安装 Spring源码下载(MAC, IDEA)

    前言:作为一个从业两年多的小菜鸟,每天都在面对spring,却从来没有编译过spring源码,没有深入的看过源码 ,感觉有点不太合适.最近突发奇想想研究一下spring源码,那么先从搭环境开始吧 ,此 ...

  5. Wine零知识学习2 —— 源码下载、构建与安装

    一.源码下载 1. 源码下载地址 wine / wine · GitLab 页面如下: 2. 源码下载 使用以下命令下载wine源码(需要事先准备好源码放置目录): git clone https:/ ...

  6. spring源码导入IDEA构建时缺失spring-cglib-repack和spring-objenesis-repack包的解决方案

    今天阅读spring源码,当用idea构建了spring源码后,发现缺失spring-cglib-repack和spring-objenesis-repack这两个依赖. 在项目的build.grad ...

  7. spring 源码下载地址

    https://github.com/spring-projects/spring-framework/tags 引自:http://blog.csdn.net/liulihui1988/articl ...

  8. spring源码导入IDEA构建时报org.springframework.oxm.jaxb.test不存在问题的解决方案(spring-oxm缺少castor和jaxb)

    spring-oxm缺少castor和jaxb 解决方案: 然后重新build一下即可.

  9. Spring源码解析(一)---spring源码的下载编译

    前言 spring是一种开源的轻量级的 Io C 和AOP 的容器框架,具体原理操作配置在本人写的spring框架分类中详细介绍了,spring框架详解.我们知道了如何使用以及它的基本特征,但是对其内 ...

  10. Spring 源码学习一: 使用Gradle 构建Spring 源码环境

    Gradle安装 下载Gradle: https://gradle.org/releases/ 选择安装的版本: 6.x 以上 选择版本后,点击下载. 配置环境变量: unzip gradle-6.8 ...

最新文章

  1. 全网最简单的dubbo源码调试,建议点赞收藏!!!
  2. 直线职权::参谋职权::职能职权
  3. 用JS读取XML文件
  4. 计算机组成原理第4章-指令系统
  5. C# 视频监控系列(13):H264播放器——控制播放和截图
  6. spring+springmvc+maven+mongodb
  7. Git之多个用户ID适配
  8. MySQL 授予普通用户PROCESS权限
  9. BZOJ1604 洛谷2906:[USACO2008 OPEN]Cow Neighborhoods 奶牛的邻居——题解
  10. 关于CF平台中基础服务的监控方案
  11. python管道_python中管道
  12. 如何使用Navicat给表设置唯一索引
  13. Pixhawk原生固件PX4之调节怠速
  14. 北上广深不相信电单车 共享单车终究走向“死“胡同?
  15. 2021年6月编程语言排行来了!!
  16. complicated用法
  17. VXI和PXI的区别
  18. u盘插电脑计算机卡了,电脑插U盘就卡住是怎么回事 几个步骤轻松解决电脑卡顿故障...
  19. 1主2从基于GKE搭建k8s集群-无需科学上网
  20. Mybatis传递单个参数

热门文章

  1. 几款Android 应用自动化测试工具
  2. 最佳的75个安全检测工具
  3. STC12C5A60S2在LCD1602基本显示程序
  4. 数据库宿舍管理系统MySQL表_数据库课程设计报告—宿舍管理系统.doc
  5. 阿里巴巴矢量图标库的引入——symbol类型的使用——阿里图标组件封装
  6. 【微信小程序使用阿里巴巴矢量图标库】
  7. 铨顺宏RFID:应用超高频RFID技术智能档案管理系统
  8. 【官方】下载最新adb及安装驱动的方法
  9. 爱客影视 程序存在文件写入漏洞 分析
  10. Auto Layout详解