编译spring-framework源码

2020-03-22  本文已影响0人  程序员老帮菜

这篇文章来源是源于最近在学习spring源码,就从github上下载了源码,进行导入到idea,期间遇到很多问题,故作为记录
编译期间遇到很多问题,最终总结出此文档,希望帮助到有需要的人,如果有用,记得评论区回复

步骤

  1. 下载源码,spring5最新源码

  2. 修改gradle配置

  3. 导入IDEA

  4. 新建自己的module

工具

下载源码


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


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

  1. github非国内地址,且无国内镜像,下载很慢,只有十几K,国内也有类似github的网站,如码云,下载会快很多

提供一个码云地址


    https://gitee.com/wuchenliang/spring-framework.git


    git clone https://gitee.com/wuchenliang/spring-framework.git

修改spring源码 gradle配置

  1. 临时去除 spring-aspects 模块

  2. 修改 maven 仓库地址

在源码跟目录


pluginManagement {

repositories {

//添加阿里云仓库,提高编译速度

maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }

maven { url 'https://maven.aliyun.com/repository/spring' }

//网上很多文章是注释掉一下仓库的,但是注释掉会遇到有些jar包在阿里镜像不存在,仍然编译失败,因此只是增加阿里镜像地址

gradlePluginPortal()

maven { url 'https://repo.spring.io/plugins-release' }

}

}

apply from: "$rootDir/gradle/build-cache-settings.gradle"

include "spring-aop"

// 去除 aspects 模块

//include "spring-aspects"

include "spring-beans"

include "spring-context"


repositories {

              //添加阿里云仓库,提高编译速度

maven { url 'https://maven.aliyun.com/repository/central' }

maven { url 'https://maven.aliyun.com/repository/spring' }

maven { url "https://repo.spring.io/snapshot" }

//网上很多文章是注释掉一下仓库的,但是注释掉会遇到有些jar包在阿里镜像不存在,仍然编译失败,因此只是增加阿里镜像地址

mavenCentral()

maven { url "https://repo.spring.io/libs-spring-framework-build" }

}


repositories {

maven { url 'https://maven.aliyun.com/repository/central' }

maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }

mavenCentral()

gradlePluginPortal()

}

源码导入IDEA


设置项目环境


spring官方编译指导


// 先编译 spring-oxm

1. Precompile `spring-oxm` with `./gradlew :spring-oxm:compileTestJava`

2. Import into IntelliJ (File -> New -> Project from Existing Sources -> Navigate to directory -> Select build.gradle)

// 排除 spring-aspects,编译完spring-oxm与spring-core后将注释打开,重新编译整个工程

3. When prompted exclude the `spring-aspects` module (or after the import via File-> Project Structure -> Modules)

// spring-core 与 spring-oxm

需要首先编译

4. `spring-core ` and `spring-oxm` should be pre-compiled due to repackaged dependencies.

开始编译

编译spring-oxm

编译spring-core

编译 spring-aspects

编译 spring-context

其他模块,有需要可以都编译下,操作相同

编译成功的工程展示

FAQ

编译报错,提示jar包或maven仓库超时

编译太慢

如果参考此文档还是有问题,可以评论区留言

下次增加个module试下

上一篇 下一篇

猜你喜欢

热点阅读