windows下使用 intellij idea 編譯 kafka 源碼環境
1. 從 GitHub 網站,git clone kafka 源碼
2. 下載安裝好 gradle,scala
2.1 從 dependencies.gradle 文件中找到 gradle 的版本,然後下載指定版本,並配置好 GRADLE_HOME 環境變量
3. 進入 kafka 項目目錄,依次執行 gradle wrapper,gradle idea,gradle build –exclude-task test
4. 將工程導入到 idea
4.1 啟動主類 kafka.Kafka
4.2 program arguments:config/server.properties
4.3 把 config 目錄下的 log4j.properties 拷貝到 core/src/main/resources 目錄
4.4 File -> Project Structure -> Modules
5. 啟動程序
然而,大部分情況下,日志不會打印出來,配置一下 core 模塊的 log4j 依賴
找到 build.gradle 文件中的 project(‘:core’),修改對應的 log4j 依賴,然後重新執行 gradle idea,重新導入 idea 中
project(':core') { println "Building project 'core' with Scala version ${versions.scala}" apply plugin: 'scala' // scaladoc generation is configured at the sub-module level with an artifacts // block (cf. see streams-scala). If scaladoc generation is invoked explicitly // for the `core` module, this ensures the generated jar doesn't include scaladoc // files since the `core` module doesn't include public APIs. scaladoc { enabled = false } if (userEnableTestCoverage) apply plugin: "org.scoverage" archivesBaseName = "kafka_${versions.baseScala}" dependencies { compile project(':clients') compile project(':metadata') compile project(':raft') compile libs.argparse4j compile libs.jacksonDatabind compile libs.jacksonModuleScala compile libs.jacksonDataformatCsv compile libs.jacksonJDK8Datatypes compile libs.joptSimple compile libs.metrics compile libs.scalaCollectionCompat compile libs.scalaJava8Compat compile libs.scalaLibrary // only needed transitively, but set it explicitly to ensure it has the same version as scala-library compile libs.scalaReflect compile libs.scalaLogging compile libs.slf4jApi compile libs.slf4jlog4j compile libs.log4j compile(libs.zookeeper) { // exclude module: 'slf4j-log4j12' // exclude module: 'log4j' } // ZooKeeperMain depends on commons-cli but declares the dependency as `provided` compile libs.commonsCli compileOnly libs.log4j testCompile project(':clients').sourceSets.test.output testCompile libs.bcpkix testCompile libs.mockitoCore testCompile libs.easymock testCompile(libs.apacheda) { exclude group: 'xml-apis', module: 'xml-apis' // `mina-core` is a transitive dependency for `apacheds` and `apacheda`. // It is safer to use from `apacheds` since that is the implementation. exclude module: 'mina-core' } testCompile libs.apachedsCoreApi testCompile libs.apachedsInterceptorKerberos testCompile libs.apachedsProtocolShared testCompile libs.apachedsProtocolKerberos testCompile libs.apachedsProtocolLdap testCompile libs.apachedsLdifPartition testCompile libs.apachedsMavibotPartition testCompile libs.apachedsJdbmPartition testCompile libs.junitJupiter testCompile libs.slf4jlog4j testCompile(libs.jfreechart) { exclude group: 'junit', module: 'junit' } }
目標就是把下圖的 log4j 依賴配置好。
到此這篇關於windows下使用 intellij idea 編譯 kafka 源碼環境的文章就介紹到這瞭,更多相關 idea 編譯 kafka 源碼內容請搜索WalkonNet以前的文章或繼續瀏覽下面的相關文章希望大傢以後多多支持WalkonNet!
推薦閱讀:
- Android Gradle 三方依賴管理詳解
- Java用 Gradle配置compile及implementation和api的區別
- IntelliJ IDEA中Project與Module的概念以及區別
- 關於Assert.assertEquals報錯的問題及解決
- 使用Composing builds提升Android編譯速度