01、Spring5源码编译之Gradle

10 篇文章 0 订阅
2 篇文章 0 订阅

需要使用gradle进行编译Spring的可以参考。研读编译脚本和网上文章经过测试现在可以编译下载的所有Spring版本源码。

写出来给大家共享,主要关注2点就可以解决编译问题。本文采用idea2020.3和idea2019.3完成编译。

0、下载源码和gradle地址

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

https://services.gradle.org/distributions/

1、gradle版本

编译的gradle版本一定跟release中gradle版本一致,再说详细点就是kotlin的版本需要一致,因为要用kotlin进行编译。

用idea和命令行的gradle可能不一样。因此需要指定idea的gradle版本跟Spring源码一致。

1.1、导入项目

导入后先停止编译过程进行配置修改

1.2、修改gradle离线下载配置

distributionUrl=file:///G:/Software/Gradle/gradle-4.10.3-bin.zip

1.3、修改gradle.properties配置

#新增如下配置,解决heap堆内存空间不够问题
org.gradle.jvmargs=-Xms2048m -Xmx4096m 
org.gradle.caching=true
org.gradle.parallel=true
gradlePropertiesProp=gradlePropertiesValue
sysProp=shouldBeOverWrittenBySysProp
systemProp.system=systemValue
org.gradle.daemon=true
org.gradle.configureondemand=true

1.3、设置idea的参数

  • jdk参数

  • gradle参数

5.1.X版本:没研究为什么需要指定gradle-wrapper为spring自带的配置文件:spring-framework-5.1.19.RELEASE\gradle\wrapper\gradle-wrapper.properties

5.2.X版本

 

2、下载源地址修改

这个网上很多就不详细叙述,有个关键点要说一下,就是要覆盖所有的gradle脚本的repositories源地址(或者搜索mavenCentral)

因为每个release版本的gradle脚本可能略有不同,release5.1.19在docs.gradle有repositories,而release5.1.13就么有。

将所有地方都拷贝上阿里云源,感谢阿里。

maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' }

maven { url 'https://maven.aliyun.com/nexus/content/repositories/jcenter' }

3、进行编译

4、常见问题解决

4.1、gradle参数设置错误会出现以下问题

org.jetbrains.kotlin.idea.configuration.KotlinMPPGradleProjectResolver.createModule(KotlinMPPGradleProjectResolver.kt:67)

4.2、授权问题

问题解决方案:注释掉 id 'io.spring.gradle-enterprise-conventions' version '0.0.2'

问题详细描述:

在编译release5.2.8版本发生,报错信息如下:

Build file 'D:\Workplace\Workspace\workspace-idea-xiangxue\spring-framework-5.2.8.RELEASE\build.gradle' line: 6

Error resolving plugin [id: 'io.spring.gradle-enterprise-conventions', version: '0.0.2']
> Could not resolve all dependencies for configuration 'detachedConfiguration5'.
   > Could not determine artifacts for io.spring.gradle-enterprise-conventions:io.spring.gradle-enterprise-conventions.gradle.plugin:0.0.2
      > Could not get resource 'https://repo.spring.io/plugins-release/io/spring/gradle-enterprise-conventions/io.spring.gradle-enterprise-conventions.gradle.plugin/0.0.2/io.spring.gradle-enterprise-conventions.gradle.plugin-0.0.2.jar'.
         > Could not HEAD 'https://repo.spring.io/plugins-release/io/spring/gradle-enterprise-conventions/io.spring.gradle-enterprise-conventions.gradle.plugin/0.0.2/io.spring.gradle-enterprise-conventions.gradle.plugin-0.0.2.jar'. Received status code 401 from server: Unauthorized

 

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

周易宅

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值