Kafka源码剖析
# 4.1 Kafka源码剖析之源码阅读环境搭建
首先下载源码:http://archive.apache.org/dist/kafka/1.0.2/kafka-1.0.2-src.tgz
gradle-4.8.1下载地址:https://services.gradle.org/distributions/gradle-4.8.1-bin.zip
Scala-2.12.12下载地址:https://downloads.lightbend.com/scala/2.12.12/scala-2.12.12.msi
# 4.1.1 安装配置Gradle
解压gradle4.8.-bin.zip到一个目录
配置环境变量,其中GRADLE_HOME指向gradle解压到的根目录,GRADLE_USER_HOME指向gradle的本地仓库位置。
PATH环境变量:
进入GRADLE_USER_HOME目录,添加init.gradle,配置gradle的源:
init.gradle内容:
allprojects
{
repositories
{
maven
{
url 'https://maven.aliyun.com/repository/public/'
}
maven
{
url 'https://maven.aliyun.com/nexus/content/repositories/google'
}
maven
{
url 'https://maven.aliyun.com/nexus/content/groups/public/'
}
maven
{
url 'https://maven.aliyun.com/nexus/content/repositories/jcenter'
}
all
{
ArtifactRepository repo - >
if(repo instanceof MavenArtifactRepository)
{
def url = repo.url.toString()
if(url.startsWith('https://repo.maven.apache.org/maven2/') || url.startsWith('https://repo.maven.org/maven2') || url.startsWith('https://repo1.maven.org/maven2') || url.startsWith('https://jcenter.bintray.com/'))
{
//project.logger.lifecycle "Repository ${repo.url} replaced by $REPOSITORY_URL."
remove repo
}
}
}
}
buildscript
{
repositories
{
maven
{
url 'https://maven.aliyun.com/repository/public/'
}
maven
{
url 'https://maven.aliyun.com/nexus/content/repositories/google'
}
maven
{
url 'https://maven.aliyun.com/nexus/content/groups/public/'
}
maven
{
url 'https://maven.aliyun.com/nexus/content/repositories/jcenter'
}
all
{
ArtifactRepository repo - >
if(repo instanceof MavenArtifactRepository)
{
def url = repo.url.toString()
if(url.startsWith('https://repo1.maven.org/maven2') || url.startsWith('https://jcenter.bintray.com/'))
{
//project.logger.lifecycle "Repository ${repo.url} replaced by $REPOSITORY_URL."
remove repo
}
}
}
}
}
}
保存并退出,打开cmd,运行:
设置成功。
# 4.1.2 Scala的安装和配置
双击安装
添加gradle的bin目录到PATH中。
打开cmd,输入 scala 验证:
输入:quit退出Scala的交互式环境。
# 4.1.3 Idea配置
idea安装Scala插件:
# 4.1.4 源码操作
解压源码:
打开CMD,进入kafka-1.0.2-src目录,执行:gradle
结束后,执行gradle idea(注意不要使用生成的gradlew.bat执行操作)
idea导入源码:
选择Gradle
上次更新: 2023/08/10, 16:25:16