1.spring源码编译--会出现的问题。以及步奏

spring源码编译遇到的问题:

首先github上下载spring太慢,可以使用码云的地址:

https://gitee.com/wangxuwen/spring-framework/tree/v5.2.0.RELEASE/

安装gradle–并配置环境变量

选择自己合适的版本,这里使用5.6.2

gradle下载地址: https://services.gradle.org/distributions/

mac版本下:

vi ~/.bash_profile

#GRADLE
GRADLE_HOME=/Users/qinxy/software/gradle-5.6.2
PATH=$PATH:$GRADLE_HOME/bin
export GRADLE_HOME GRADLE_USER_HOME PATH

source ~/.bash_profile

高版本和低版本都会遇到问题,这里建议安装gradle5.x版本的

gradle-5.6.2-bin

打开源码:

在E:\www\Spring-Framewor5.2\gradle\wrapper\gradle-wrapper.properties下

防止它重复下载gradle

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

idea的kotlin插件版本更换为低版本:kotlin-plugin-1.4.0

spring源码里gradle的镜像改为:

build.gradle文件

#这里不改的话,编译的时候会报错
id "com.gradle.build-scan" version "3.8.1"
buildscript下
repositories {
       maven{ url 'https://maven.aliyun.com/nexus/content/groups/public/' }
       maven{ url 'https://maven.aliyun.com/nexus/content/repositories/jcenter'}
   }
   configurations.all上面添加
   跟
   resolutionStrategy {
			cacheChangingModulesFor 0, "seconds"
		}
同级别
   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" }
		}

然后加载编译

bash:gradlew :command not found

mac下执行会报错,一般是权限不足,在gradle安装目录下

chmod +x gradlew

./gradlew :spring-oxm:compileTestJava

详细步奏https://blog.csdn.net/qq_40670946/article/details/102989709

Failed to find KotlinGradleProjectData for GradleSourceSetData
这个问题出现的原因是因为你的idea的kotlin插件版本导致的,我的kotlin插件升级成最新的1.6x
mac电脑idea–版本2021.3 —对应kotlin1.6x
win电脑idea–版本2020.1.3–对应kotlin1.3x

在框架下新建demo时,点击build常见错误

Execution failed for task ':spring-debug:checkstyleMain'.
> Checkstyle rule violations were found. See the report at: file:///Users/gaoxiang/git/spring-framework/spring-debug/build/reports/checkstyle/main.html
  Checkstyle files with violations: 1
  Checkstyle violations by severity: [error:2]

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.



出现以上错误是因为spring使用了ant风格的代码检查,所有的检查规则都在–源码/src/checkstyle/checkstyle.xml里面做了配置,如果不想被这些检查烦扰到,可以全部注释掉:

如果不想全部注释掉,可以这样改/src/checkstyle/checkstyle.xml
<!-- Root Checks -->
<!-- 检查SpringHeader 每个类开头部分必须是版权声明-->
<module name="io.spring.javaformat.checkstyle.check.SpringHeaderCheck">
  <property name="fileExtensions" value="java" />
  <property name="headerType" value="apache2"/>
  <property name="headerCopyrightPattern" value="20\d\d-20\d\d"/>
  <property name="packageInfoHeaderType" value="none"/>
</module>
<!-- 检查HideUtilityClassConstructor 工具类应私有化构造器 并声明为final 避免被创建对象-->
<module name="com.puppycrawl.tools.checkstyle.checks.design.HideUtilityClassConstructorCheck" />

或者在demo类这样写:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值