Java   发布时间:2022-04-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了基于Gradle的Spring源码下载及构建技巧大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

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 ,下载完成后,解压源码包会看到如下图所示的文件目录。

file

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操作系统为例。
第一步,配置环境变量,如下图所示。

file

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

file

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

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

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

@H_675_22@ 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 8s 1 actionable task: 1 executed

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

@H_675_22@ ---------------------------------------------------------------------- Spring Framework - Eclipse/STS project impart guide This script will guide you through the process of imporTing the Spring Framerork projects into Ec1ipse or the Spring Tool Suite STS) it is recommended that you have a recent version of Eclipse or STs. As a bare minimum you wi11 need Eclipse with full Java 8 support, the AspectJ Development Tools (AJDT), and the Groovy Compiler. If you need to download and install Eclipse or STS, please do that now by 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 each of the spring-* subprojects. This happens via the built-in "Gradle wrapper" script (./gradlew in this directory). If this is your first time using the Gradle wrapper, this step may take a fewr minutes while a Gradle diStribution is downloaded for you.

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

@H_675_22@ BUILD SUOCESSFUL in 6s 6 actionable tasks: 6 executed ---------------------------------------------------------------------- STEP 4: Import root project into Ec1ipse/STS Follow the project inport steps listed in step 2 above to inport the root 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”按钮,再单击“Finish”按钮,如下三图所示。

file

file

file

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

file

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

file

3 Gradle构建过程中的坑

如果项目环境一直无法构建成功,类图无法自动生成,那么你一定是踩到了一个坑。
第一步,单击View→Tool Windows→Gradle命令,如下图所示。

file

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

file

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

file

第三步,出现错误显然跟Gradle没有任何关系,解决办法:
(1)关闭IDEA,打开任务管理器,结束跟Java有关的所有进程。
(2)找到JAVA_HOME→jre→lib目录,将tools.jar重命名为tools.jar.bak。
(3)重启IDEA,再次单击刷新按钮,等待构建完成。

原创不易,坚持很酷,都看到这里了,小伙伴记得点赞、收藏、在看,一键三连加关注!如果你觉得内容太干,可以分享转发给朋友滋润滋润!

大佬总结

以上是大佬教程为你收集整理的基于Gradle的Spring源码下载及构建技巧全部内容,希望文章能够帮你解决基于Gradle的Spring源码下载及构建技巧所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: