如何在intellij idea中调试elasticsearch源代码

2022-08-06 15:51:47 浏览数 (1)

准备

本文以Elasticsearch 6.6 为例,介绍使用IDEA调试Elasticsearch源码的方法。

使用到的工具和版本如下:

组件

版本

jdk

corretto-11.0.16

gradle

5.6.4

groovy

4.0.4

IntelliJ IDEA

2022.1

IDEA选择

对比:分别试过IntelliJ IDEA 2018.2.4和Visual Studio Code遇到一些障碍最后还是在IntelliJ IDEA 2022.1顺利通过。IntelliJ IDEA 2018.2.4直接崩溃闪退。vscode有两个问题,代码debug和groovy暂时放弃。

辅助:能自动下载jdk,帮助选择openjdk版本和提供下载地址。

下载jdk下载jdk

jdk选择和下载

jdk版本参考

gradle和jdk兼容性矩阵

兼容性矩阵

Java version

First Gradle version to support it

8

2.0

9

4.3

10

4.7

11

5.0

12

5.4

13

6.0

14

6.3

15

6.7

16

7.0

17

7.3

18

7.5

gradle下载和安装

用户主目录不用设置在系统盘下

distributionBase=GRADLE_USER_HOME

全局变量:GRADLE_USER_HOME设置成非系统盘

groovy选择

Gradle is tested with Groovy 1.5.8 through 4.0.0.Gradle plugins written in Groovy must use Groovy 3.x for compatibility with Gradle and Groovy DSL build scripts.

下载Elasticsearch源码

新建项目新建项目

代码地址:https://github.com/elastic/elasticsearch.git

选择路径选择路径
下载中下载中
选择分支选择分支

选择分支:6.6

编译

./gradlew assemble./gradlew assemble

运行

./gradlew run --debug-jvm./gradlew run --debug-jvm

验证

在浏览器中验证在浏览器中验证

遇到问题和解决

  • jdk版本问题
代码语言:shell复制
Unable to start the daemon process.
This problem might be caused by incorrect configuration of the daemon.
For example, an unrecognized jvm option is used.
Please refer to the User Manual chapter on the daemon at
  • gradle版本问题
代码语言:shell复制
Cause: startup failed:
settings file 'E:workspaceeselasticsearchsettings.gradle': 1: unable to resolve class org.elasticsearch.gradle.Version
@ line 1, column 1.
import org.elasticsearch.gradle.Version
^
1 error
  • groovy版本问题
代码语言:shell复制
I am getting this exception?java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7  and java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.reflection.ReflectionCache) when i run the spring
  • idea 闪崩问题 看日志没有什么发现,只好升级版本
  • resource 访问 "Connect to artifacts.elastic.co:443"
代码语言:java复制
   // 这个资源443:
  compile "com.amazonaws:aws-java-sdk-s3:${versions.aws}"
  compile "com.amazonaws:aws-java-sdk-kms:${versions.aws}"
  compile "com.amazonaws:aws-java-sdk-core:${versions.aws}"
代码语言:shell复制
Could not resolve all task dependencies for configuration ':plugins:repository-s3:runtime'.
Could not resolve com.amazonaws:aws-java-sdk-s3:1.11.406.
Required by:
project :plugins:repository-s3
Could not resolve com.amazonaws:aws-java-sdk-s3:1.11.406.
Could not get resource 'https://artifacts.elastic.co/maven/com/amazonaws/aws-java-sdk-s3/1.11.406/aws-java-sdk-s3-1.11.406.pom'.
Could not GET 'https://artifacts.elastic.co/maven/com/amazonaws/aws-java-sdk-s3/1.11.406/aws-java-sdk-s3-1.11.406.pom'.
Connect to artifacts.elastic.co:443 [artifacts.elastic.co/34.120.127.130] failed: Connection timed out: connect
Could not resolve com.amazonaws:aws-java-sdk-s3:1.11.406.
Could not get resource 'https://jcenter.bintray.com/com/amazonaws/aws-java-sdk-s3/1.11.406/aws-java-sdk-s3-1.11.406.pom'.
Could not GET 'https://jcenter.bintray.com/com/amazonaws/aws-java-sdk-s3/1.11.406/aws-java-sdk-s3-1.11.406.pom'.

配置国内云仓库

代码语言:java复制
 //  settings.gradle
buildscript {
  repositories {
    //对应google()
    maven {url 'https://maven.***.com/repository/google'}
    //对应jcenter()
    maven {url 'https://maven.***.com/repository/jcenter'}
    //公共库
    maven {url 'https://maven.***.com/repository/public'}

  }
}
  • gradle三方包占用系统盘问题

总结

按照上述步骤就跑起来,可以规避我踩过坑。如果文中有没阐述清楚,欢迎在评论区留言。

0 人点赞