- 一. 下载源码
- 二. 编译源码
- 三. 编译oxm 模块
- 四. 导入IDE
- 五. 排除spring-aspects 模块
https://github.com/spring-projects/spring-framework/tree/v5.2.0.RELEASE 在Spring的GitHub仓库中, 选择5.2.0.RELEASE的版本进行下载到本地. 可以下载zip 包, 或者使用git clone命令进行下载
在源码的readme中, 有编译源码的教程 ,点击下面的超链接. 跳转到如下的网址 https://github.com/spring-projects/spring-framework/wiki/Build-from-Source 点击页面最下方导入到ide的方法.
跳转到如下的页面 https://github.com/spring-projects/spring-framework/blob/master/import-into-idea.md 根据链接中内容, 需要如下的这几步来进行编译操作 .
Precompile spring-oxm with ./gradlew :spring-oxm:compileTestJava Import into IntelliJ (File -> New -> Project from Existing Sources -> Navigate to directory -> Select build.gradle) When prompted exclude the spring-aspects module (or after the import via File-> Project Structure -> Modules) Code away
首先需要预编译 spring-oxm 下载的源码中, 有gradlew文件, 此文件会自动去下载gradle
用编辑器打开build.gradle 文件, 此文件, 类似于maven的pom.xml文件. 在此文件中配置阿里云的进行, 便于快速下载依赖的jar包.
在文件的开头处, 添加阿里云镜像.
repositories {
maven{ url 'https://maven.aliyun.com/nexus/content/groups/public/' }
maven{ url 'https://maven.aliyun.com/nexus/content/repositories/jcenter'}
}
接着在文件中搜索allprojects 在其底部找到repositories, 也添加上阿里云的依赖.
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" }
}
三. 编译oxm 模块
保存上一步修改的文件, 在源码的目录中 cmd中执行如下的命令
gradlew :spring-oxm:compileTestJava
进行编译 . 等待完成后, 可以看到编译成功的信息.
按照如下的步骤, 进行项目的导入.
导入到idea 后, 需要等待其jar包的下载.
经过10 分钟的等待后 , 可以看到jar包下载完成.
之所以排除spring-aspects , 是因为spring-aspects 使用的是自己的编译器, 会影响其他模块的编译和加载, 打开spring-aspects 模块中某一个类, 可以看到其飘红的代码. 选择spring-aspects 模块, 右键 , 选择Load/Unload Modules