• 使用 IntelliJ IDEA 构建 Spring Framework 5.3.18 源码问题解决


    源码版本

    1、下载地址:https://github.com/spring-projects/spring-framework/tags
    2、选择要构建的源码版本并下载,例如:5.3.18
    

    相关环境

    1、操作系统:Windows10
    2、JDK 版本:Jdk11
    3、IDE 工具:IntelliJ IDEA 2021.3.3
    4、项目构建工具:Gradle 7.3.3
    

    使用 IntelliJ IDEA 构建 Spring 源码步骤

    1、打开 cmd 命令行工具,进入当前项目根目录,然后使用命令 gradlew.bat :spring-oxm:compileTestJava 预编译 spring-oxm 模块
    2、将项目导入 IntelliJ IDEA,步骤为 File -> New -> Project from Existing Sources -> 选择项目根路径下的 build.gradle 导入
    

    修改 jdk 版本(好像不改也行,但需要保证 java -version 命令的结果是 java 11.xxx)

    1、修改 spring-oxm 模块下的 spring-oxm.gradle 配置文件:
      将 JavaVersion.VERSION_1_8 改为 JavaVersion.VERSION_11
    
    2、修改 gradle 模块下的  toolchains.gradle 配置文件:
      将 JavaLanguageVersion.of(8) 改为 JavaLanguageVersion.of(11)。
      将 sourceCompatibility = JavaVersion.VERSION_1_8 改为 sourceCompatibility = JavaVersion.VERSION_11。
      将 jvmTarget = '1.8' 改为 jvmTarget = '11'。
    

    遇到的问题及解决方法

    预编译 spring-oxm 模块报错:org.gradle.process.internal.ExecException: Process 'command 'git'' finished with non-zero exit value 128

    多半是因为你的项目源码是通过下载的方式获得,而非通过 git clone 命令克隆而来,可以不解决。
    如果有强迫症,非要解决,建议通过 git clone 命令去克隆项目源码,然后重新编译。
    

    缺少 spring-cglib-repack-xxx.jar 和 spring-objenesis-repack-xxx.jar 依赖

    解决方案:
    【方法一】在源码项目根路径下执行:gradle objenesisRepackJar、gradle cglibRepackJar。
    【方法二】在 IntelliJ IDEA 的侧边工具打开 gradle,分别双击 spring-core -> Tasks  -> other 下的 objenesisRepackJar 和 cglibRepackJar。
    以上两种方法均会在项目的 spring-core\build\libs 目录下生成所需 jar 包。
    

    在运行某些测试类时,IntelliJ IDEA 报错:Command line is too long …… 的解决办法

    解决方案:
    找到当前项目 .idea\workspace.xml 文件中的 <component name="PropertiesComponent">,并在其中加一行 <property name="dynamic.classpath" value="true"/>,然后重新运行。
    

    运行时报错:No tests found for given includes: [**/Tests.class, **/Test.class]......

    报错详情:
    Execution failed for task ':模块名称:test'.
    > No tests found for given includes: [**/*Tests.class, **/*Test.class](include rules) [......](--tests filter)
    
    解决方案:
    配置测试运行器为 IntelliJ IDEA 即可。IDEA 中的具体步骤:
    1、进入 Gradle 设置页面:File -> Settings -> Build,Execution,Deployment -> Build Tools -> Gradle
    2、修改:将 Gradle Projects 面板中的 Run tests using 选项值改为 IntelliJ IDEA
    
    【说明】在 Run tests using 选项列表中,为 Gradle 项目指定测试运行器,区别如下:
    1、Gradle:选择此选项将使用 Gradle 作为测试运行器。结果是在持续集成(CI)服务器上获得相同的测试结果,在命令行中运行的测试将始终在 IDE 中运行。
    2、IntelliJ IDEA:选择此选项可将测试过程委派给 IntelliJ IDEA。在这种情况下,IntelliJ IDEA 使用 JUnit 测试运行器,并且由于增量编译,测试运行得更快。
    3、Choose pre test:选择此选项可配置每个测试专门使用哪个测试运行器(Gradle 或 IntelliJ IDEA)。
    

    出现 AutowiredAnnotationBeanPostProcessor.java:542: 错误: 对 determineRequiredStatus 的引用不明确

    报错详情:
    spring-beans\src\main\java\org\springframework\beans\factory\annotation\AutowiredAnnotationBeanPostProcessor.java:542: 错误: 对determineRequiredStatus的引用不明确
    return determineRequiredStatus(
    AutowiredAnnotationBeanPostProcessor 中的方法 determineRequiredStatus(MergedAnnotation<?>) 和 AutowiredAnnotationBeanPostProcessor 中的方法 determineRequiredStatus(AnnotationAttributes) 都匹配
      
    解决方案:
    将 return determineRequiredStatus(ann.asMap(mergedAnnotation -> new AnnotationAttributes(mergedAnnotation.getType()))); 
    更改为 return determineRequiredStatus(ann.<AnnotationAttributes> asMap(mergedAnnotation -> new AnnotationAttributes(mergedAnnotation.getType())));
    

    出现 CoroutinesUtils.java:74: 警告: [deprecation] AccessibleObject中的isAccessible()已过时

    报错详情:
    spring-core\src\main\java\org\springframework\core\CoroutinesUtils.java:74: 警告: [deprecation] AccessibleObject中的isAccessible()已过时
    if (method.isAccessible() && !KCallablesJvm.isAccessible(function)) {
    
    解决方案:
    在 org.springframework.core.CoroutinesUtils.invokeSuspendingFunction(Method method, Object target, Object... args) 方法上加 @SuppressWarnings("deprecation") 注解即可。 
    
  • 相关阅读:
    一维函数指针数组和二维函数指针数组demo
    等着新工作
    SSRS常见问题解决方案
    速度
    javascript 满足多层treeview的各种勾选
    vue create 初步解析以及定制化修改
    leveldb总结
    秋招总结场景设计题
    NOSQL: mongoDB windows
    更新webconfig配置文件
  • 原文地址:https://www.cnblogs.com/qubo520/p/16044387.html
Copyright © 2020-2023  润新知