问题
最近在看Kafka源码,从网上download最新版本3.0.0源码后需要用gradle进行项目的build,但在build过程中一直报错:
Starting Gradle Daemon… Gradle Daemon started in 2 s 127 ms
Configure project : Starting build with version 3.0.0 using Gradle
7.1.1, Java 1.8 and Scala 2.13.6
<ij_msg_gr>Gradle import errors<ij_msg_gr><ij_nav>D:\Study\tech\Kafka\source_code\kafka-3.0.0-src\build.gradle<ij_nav> root
project ‘kafka-3.0.0-src’: Unable to build Kotlin project
configuration Details:
org.gradle.api.internal.tasks.DefaultTaskContainer$TaskCreationException:
Could not create task
‘:spotlessInternalRegisterDependencies’.Caused by:
org.gradle.api.tasks.TaskInstantiationException: Could not create task
of type ‘RegisterDependenciesTask’.Caused by:
java.lang.UnsupportedClassVersionError:
org/eclipse/jgit/lib/AnyObjectId has been compiled by a more recent
version of the Java Runtime (class file version 55.0), this version of
the Java Runtime only recognizes class file versions up to 52.0FAILURE: Build failed with an exception.
由报错看上去是版本问题,但检查了jdk以及Scala的版本也是官网推荐的,那只能是Gradle版本的问题了。去网上search了下,也是建议降低Gradle版本。于是开始行动。。。。
解决
手工从Gradle官网( https://gradle.org/releases/ )下载了version 6.8.1,
修改idea Gradle build的配置:
尝试重新build,but…still
Configure project : Starting build with version 3.0.0 using Gradle
7.1.1, Java 1.8 and Scala 2.13.6FAILURE: Build failed with an exception.
Where: Build file ‘D:\Study\tech\Kafka\source_code\kafka-3.0.0-src\build.gradle’ line:
2151What went wrong: A problem occurred evaluating root project ‘kafka-3.0.0-src’. Failed to apply plugin class
‘com.github.jengelman.gradle.plugins.shadow.ShadowBasePlugin’.
This version of Shadow supports Gradle 7.0+ only. Please upgrade.
于是弃用kafka最新版,降到 2.7.1,然后重新import项目 build ,成功!!!
总结
确实要感谢工具报错提示的准确性。
项目的基础运行环境版本 + 项目本身的版本 + build工具的版本 + 开发环境的版本 一定要注意兼容。