Spring 源码编译遇到的坑

10 篇文章 0 订阅
  • 系统 : Mac

  • idea版本 :2019.3

  • gradle :两个版本,4.10.3 和 5.5.1

  • Spring 版本:v5.1.17.RELEASE

按照官方给的说明:

image-20200730165456111

  1. 下载源码,先不要打开,进入源码目录,执行 ./gradlew :spring-oxm:compileTestJava,这个时候它会自动下载gradle 4.10.3 (好吧,我得承认,前前后后,gradle的版本我下载了n个, Spring 的源码版本我也下载了n个, 只有这个编译通过了)
  2. 导入项目 Import into IntelliJ (File -> New -> Project from Existing Sources -> Navigate to directory -> Select build.gradle)
  3. 当你遇到提示时,可以移除 Spring-aspects 这个模块(我没遇到)
  4. 干吧

下载依赖这个情况吧,我是全局替换成了阿里云的镜像,所以就没有再改build.gradle, 在你的用户目录下新建一个init.gradle,填入以下内容

allprojects{
repositories {
    def ALIYUN_REPOSITORY_URL = 'https://maven.aliyun.com/repository/public/'
    def ALIYUN_JCENTER_URL = 'https://maven.aliyun.com/repository/jcenter/'
    def ALIYUN_GOOGLE_URL = 'https://maven.aliyun.com/repository/google/'
    def ALIYUN_GRADLE_PLUGIN_URL = 'https://maven.aliyun.com/repository/gradle-plugin/'
    all { ArtifactRepository repo ->
        if(repo instanceof MavenArtifactRepository){
            def url = repo.url.toString()
            if (url.startsWith('https://repo1.maven.org/maven2/')) {
                project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_REPOSITORY_URL."
                remove repo
            }
            if (url.startsWith('https://jcenter.bintray.com/')) {
                project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_JCENTER_URL."
                remove repo
            }
            if (url.startsWith('https://dl.google.com/dl/android/maven2/')) {
                project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_GOOGLE_URL."
                remove repo
            }
            if (url.startsWith('https://plugins.gradle.org/m2/')) {
                project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_GRADLE_PLUGIN_URL."
                remove repo
            }
        }
    }
    maven { url ALIYUN_REPOSITORY_URL }
    maven { url ALIYUN_JCENTER_URL }
    maven { url ALIYUN_GOOGLE_URL }
    maven { url ALIYUN_GRADLE_PLUGIN_URL }
}}

然后开始编译,我是遇到了各种各样的错,错误列表如下

  • Received close_notify during handshake,换了Spring版本解决的,搜索无果

  • ReadTimeOut 应该是网络慢,可以尝试换阿里云

  • fatal: not a git repository (or any of the parent directories): .git 搜索无果,建议换 Spring 版本

  • exception during working with external system: java.lang.AssertionError
    at org.jetbrains.plugins.gradle.service.project.BaseGradleProjectResolverExtension.createModule(BaseGradleProjectResolverExtension.java:154)
    at org.jetbrains.plugins.gradle.service.project.AbstractProjectResolverExtension.createModule(AbstractProjectResolverExtension.java:86) Gradle版本问题,修改 源码目录下的 gradle/wrapper/gradle-wrapper.properties

    distributionBase=GRADLE_USER_HOME
    distributionPath=wrapper/dists
    #distributionUrl=https://services.gradle.org/distributions/gradle-4.10.3-bin.zip
    distributionUrl=https://services.gradle.org/distributions/gradle-5.5.1-all.zip
    zipStoreBase=GRADLE_USER_HOME
    zipStorePath=wrapper/dists

idea的相关配置如下:

image-20200730171033814

如果,运气好的话,你应该就可以编译通过了,接下来建立测试模块

image-20200730171218978

image-20200730171303194

Hello world

如果,你建立了测试模块后,写代码没有提示,加下依赖,在你测试模块的 build.gradle里

dependencies {
    compile(project(":spring-context"))
    compile(project(":spring-beans"))
    testCompile group: 'junit', name: 'junit', version: '4.12'
}

image-20200730171411800

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值