intellij idea 编译 kafka 源码

以下是针对kafka 1.1.1版本编译流程及在idea中启动的步骤

  1. 从 GitHub 网站,git clone kafka 源码

  2. 下载安装好 gradle,scala

  3. 进入 kafka 项目目录,执行 gradle idea

  • 如果出现如下buid失败的情况
kafka-1.1.1-src gradle idea

> Configure project :
Building project 'core' with Scala version 2.11.12

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/bibo/.Trash/kafka-1.1.1-src/build.gradle' line: 552

* What went wrong:
A problem occurred evaluating root project 'kafka-1.1.1-src'.
> Failed to apply plugin [id 'org.scoverage']
   > Could not create an instance of type org.scoverage.ScoverageExtension.
      > You can't map a property that does not exist: propertyName=testClassesDir

* 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.

* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.4.1/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 2s

解决方法参考:KAFKA-7706

修改 build.gradle 文件,将org.scoverage:gradle-scoverage 版本修改,2.1.0修改为2.5.0,重新执行

buildscript {
  repositories {
    mavenCentral()
    jcenter()
  }
  apply from: file('gradle/buildscript.gradle'), to: buildscript

  dependencies {
    // For Apache Rat plugin to ignore non-Git files
    classpath "org.ajoberstar:grgit:1.9.3"
    classpath 'com.github.ben-manes:gradle-versions-plugin:0.15.0'
    classpath 'org.scoverage:gradle-scoverage:2.5.0' ## 将2.1.0修改为2.5.0
    classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.1'
  }
}
  1. BUILD SUCCESSFUL后,idea从打开源码跟目录生产的ipr(eg. kafka-1.1.1-src.ipr)文件

  2. 把 config 目录下的 log4j.properties 拷贝到 core/src/main/resources 目录

  3. 启动主类 kafka.Kafka

  4. 配置启动参数:Run->Edit Configurations ->program arguments:config/server.properties
    启动主类: kafka.Kafka

  5. 点击Run启动

  • 若启动后没有log输出,并在idea控制台出现下面信息warning信息
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder
  • 解决办法
    idea 中选择 File -> Project Structure -> Modules
    找到 core模块,打开 dependencies,将sl4j-log4j 的相关jar 包(slf4j-api-1.7.25.jar,slf4j-log4j12-1.7.25.jar,log4j-1.2.17.jar) 的scope选择为Compile(之前可能是provide或test),重新启动

https://juejin.im/post/5c94f4ed6fb9a070e4623687
https://www.cnblogs.com/allenwas3/p/9549915.html

你可能感兴趣的:(intellij idea 编译 kafka 源码)