spring-framework源码编译及导入

时间:2022-03-01 09:22:06

环境说明:

时间:2017-09-26

OS name: "mac os x", version: "10.12.4", arch: "x86_64", family: "mac"

Git version:git version 2.11.0 (Apple Git-81)

Maven: Apache Maven 3.3.9

Java version: 1.8.0_121

1. 下载spring-framework源代码

访问spring-framework的Git地址:

  https://github.com/spring-projects/spring-framework

源码下载URL:

https://github.com/spring-projects/spring-framework.git

git@github.com:spring-projects/spring-framework.git

2. 编译源码

2.1  下载Gradle工具及相关依赖

进入spring-framework下载目录,执行./gradlew

  spring-framework源码编译及导入

 

2.2 查看可编译的编译任务

按照指示,可以先查看编译任务有哪些,执行./gradlew tasks

  

 1 > Task :tasks
 2 
 3 ------------------------------------------------------------
 4 All tasks runnable from root project - Spring Framework
 5 ------------------------------------------------------------
 6 
 7 Build tasks
 8 -----------
 9 assemble - Assembles the outputs of this project.
10 build - Assembles and tests this project.
11 buildDependents - Assembles and tests this project and all projects that depend on it.
12 buildNeeded - Assembles and tests this project and all projects it depends on.
13 classes - Assembles main classes.
14 clean - Deletes the build directory.
15 jar - Assembles a jar archive containing the main classes.
16 testClasses - Assembles test classes.
17 
18 Build scan tasks
19 ----------------
20 buildScanPublishPrevious - Publishes the data captured by the last build to the build scan server.
21 
22 Build Setup tasks
23 -----------------
24 init - Initializes a new Gradle build.
25 
26 Distribution tasks
27 ------------------
28 depsZip - Builds -dist-with-deps archive, containing everything in the -dist archive plus all runtime dependencies.
29 distZip - Builds -dist archive, containing all jars and docs, suitable for community download page.
30 docsZip - Builds -docs archive containing api and reference for deployment at http://docs.spring.io/spring-framework/docs.
31 schemaZip - Builds -schema archive containing all XSDs for deployment at http://springframework.org/schema.
32 
33 Documentation tasks
34 -------------------
35 api - Generates aggregated Javadoc API documentation.
36 asciidoctor - Converts AsciiDoc files and copies the output files and related resources to the build directory.
37 dokka - Generates dokka documentation for Kotlin
38 groovydoc - Generates Groovydoc API documentation for the main source code.
39 javadoc - Generates Javadoc API documentation for the main source code.
40 jdiff - Generates a JDiff report
41 
42 Help tasks
43 ----------
44 buildEnvironment - Displays all buildscript dependencies declared in root project 'spring'.
45 components - Displays the components produced by root project 'spring'. [incubating]
46 dependencies - Displays all dependencies declared in root project 'spring'.
47 dependencyInsight - Displays the insight into a specific dependency in root project 'spring'.
48 dependencyManagement - Displays the dependency management declared in root project 'spring'.
49 dependentComponents - Displays the dependent components of components in root project 'spring'. [incubating]
50 help - Displays a help message.
51 model - Displays the configuration model of root project 'spring'. [incubating]
52 projects - Displays the sub-projects of root project 'spring'.
53 properties - Displays the properties of root project 'spring'.
54 tasks - Displays the tasks runnable from root project 'spring' (some of the displayed tasks may belong to subprojects).
55 
56 IDE tasks
57 ---------
58 cleanEclipse - Cleans all Eclipse files.
59 cleanIdea - Cleans IDEA project files (IML, IPR)
60 eclipse - Generates all Eclipse files.
61 idea - Generates IDEA project files (IML, IPR, IWS)
62 
63 Verification tasks
64 ------------------
65 check - Runs all checks.
66 test - Runs the unit tests.
67 
68 Rules
69 -----
70 Pattern: clean<TaskName>: Cleans the output files of a task.
71 Pattern: build<ConfigurationName>: Assembles the artifacts of a configuration.
72 Pattern: upload<ConfigurationName>: Assembles and uploads the artifacts belonging to a configuration.
73 
74 To see all tasks and more detail, run gradlew tasks --all
75 
76 To see more detail about a task, run gradlew help --task <task>
77 
78 
79 BUILD SUCCESSFUL in 4s
80 1 actionable task: 1 executed

2.3 执行spring的编译任务

上面罗列了很多任务,选择执行build任务,命令如下:./gradlew build

这步会编译整个工程,预计时间为一个多小时,保持网络通畅,就可以去干其他事情了

我这次编译花了53min,编译完成的截图:

  spring-framework源码编译及导入

2.4 执行导入eclipse的脚本

因为idea可以兼容eclipse的工程,故可以直接执行导入eclipse工程的初始化脚本,当然了,目前也只有eclipse的可用脚本

导入idea只有一个说明文档:import-into-idea.md

准备执行初始化,找到“import-into-eclipse” 的可执行脚本,Windows下是.bat,类Unix系统都是.sh

  spring-framework源码编译及导入

  确认本地已经安装了Eclipse开发工具,因为执行这个脚本前需要安装Eclipse,安装完成后

  执行命令:./import-into-eclipse.sh

  spring-framework源码编译及导入

  已经安装了Eclipse,点击Enter键继续,开始第一步编译工具,生成各自工程的metadata文件

  spring-framework源码编译及导入

  这步花费时间较长,我本地花费了14min

  spring-framework源码编译及导入

  完成后,点击Enter继续,开始第二步工作,导入工程到Eclipse中

  spring-framework源码编译及导入

  导入完成后,点击Enter继续,开始第三步工作,生成根目录下的metadata

  spring-framework源码编译及导入

  点击Enter继续,开始第四步工作,重新导入工程到Eclipse中

      spring-framework源码编译及导入

  至此编译完成并初始化Eclipse工程完成,第五步增加Git支持和分享

  spring-framework源码编译及导入

  大功告成,Goodbye!