gradle:gradle-4.8.1
kafka源码包 Kafka-1.0.2
scala 2.13.7
解压安装包配置环境变量
#GRADLE_HOME GRADLE_HOME=/Users/guchenfei/Source/gradle-4.8.1 export PATH=$PATH:$GRADLE_HOME/bin
验证gradle环境
gradle -version guchenfeideMacBook-Pro:~ guchenfei$ gradle -version Welcome to Gradle 4.8.1! Here are the highlights of this release: - Dependency locking - Maven Publish and Ivy Publish plugins improved and marked stable - Incremental annotation processing enhancements - APIs to configure tasks at creation time For more details see https://docs.gradle.org/4.8.1/release-notes.html ------------------------------------------------------------ Gradle 4.8.1 ------------------------------------------------------------ Build time: 2018-06-21 07:53:06 UTC Revision: 0abdea078047b12df42e7750ccba34d69b516a22 Groovy: 2.4.12 Ant: Apache Ant(TM) version 1.9.11 compiled on March 23 2018 JVM: 1.8.0_301 (Oracle Corporation 25.301-b09) OS: Mac OS X 10.16 x86_64
我们在搭建完gradle后为了加快下载依赖使用国内镜像(默认是使用国外源)
mac下修改全局gradle镜像源
在操作系统当前用户的 HOME 目录,找到 .gradle 文件夹,在这个文件夹下面创建一个文本文件 init.gradle
在此文件中加入如下代码片段:
allprojects{
repositories {
def ALIYUN_REPOSITORY_URL = 'http://maven.aliyun.com/nexus/content/groups/public'
def ALIYUN_JCENTER_URL = 'http://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')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_REPOSITORY_URL."
remove repo
}
if (url.startsWith('https://jcenter.bintray.com/')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_JCENTER_URL."
remove repo
}
}
}
maven {
url ALIYUN_REPOSITORY_URL
url ALIYUN_JCENTER_URL
}
}
}
三.安装scala
brew update brew install scala 安装成功提示 Pruned 22 symbolic links and 3 directories from /usr/local ==> Caveats ==> scala To use with IntelliJ, set the Scala home to: /usr/local/opt/scala/idea 由于我是用brew直接安装所以没有配置环境变量 验证安装是否成功 guchenfeideMacBook-Pro:~ guchenfei$ scala Welcome to Scala 2.13.6 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_301). Type in expressions for evaluation. Or try :help. scala> 1+2 val res0: Int = 3 scala> scala> :quit 出现上边表明成功四.idea搭建Scala环境 1.安装Scala插件
由于我没有搜索到该插件,采用离线安装方式
link : https://plugins.jetbrains.com/plugin/1347-scala/versions
ps:文件名不要改,保持原压缩文件导入
选择brose选中scala sdk安装位置
ps:步骤三有安装路径提示
我的是 /usr/local/opt/scala/idea/lib
ok 确认后Scala sdk配置成功,后续就可以进行Scala编程
五.kafka源码编译 1.进入Kafka源码根目录下执行gradleguchenfeideMacBook-Pro:kafka-1.0.2-src guchenfei$ gradle Starting a Gradle Daemon (subsequent builds will be faster) Download https://repo.maven.apache.org/maven2/org/scoverage/gradle-scoverage/2.1.0/gradle-scoverage-2.1.0.pom Download https://repo.maven.apache.org/maven2/org/scala-lang/scala-library/2.11.11/scala-library-2.11.11.jar Download https://repo.maven.apache.org/maven2/org/scala-lang/modules/scala-xml_2.11/1.0.5/scala-xml_2.11-1.0.5.jar ....... BUILD SUCCESSFUL in 44s 1 actionable task: 1 executed2.源码下运行gradle idea,编译成idea工程(创建工程索引)
guchenfeideMacBook-Pro:kafka-1.0.2-src guchenfei$ gradle idea .... Download http://maven.aliyun.com/nexus/content/repositories/jcenter/org/reflections/reflections/0.9.11/reflections-0.9.11.pom Download http://maven.aliyun.com/nexus/content/repositories/jcenter/org/reflections/reflections/0.9.11/reflections-0.9.11.jar Download http://maven.aliyun.com/nexus/content/repositories/jcenter/org/reflections/reflections/0.9.11/reflections-0.9.11-sources.jar Download http://maven.aliyun.com/nexus/content/repositories/jcenter/log4j/log4j/1.2.15/log4j-1.2.15.pom > Task :idea Generated IDEA project at file:///Users/guchenfei/Source/kafka-1.0.2-src/kafka-1.0.2-src.ipr BUILD SUCCESSFUL in 1m 22s 22 actionable tasks: 22 executed六.idea打开该源码
打开setting 配置gradle
重新指定gradle位置,与上边配置的相同
ps:如果需要setup scala sdk参照四.2进行
此刻我们可以正常阅读源码了



