ElasticSearch源码分析(一):源码调试环境搭建(将ElasticSearch源码导入IDEA)
本源码阅读环境是基于ElasticSearch 7.8.0版本,此版本需要IDEA版本至少为2020.1版
一、 准备工作:
- 下载ElasticSearch 7.8.0 源码
- 下载ElasticSearch 7.8.0发行版
- 安装Gradle(最低版本要求详见源代码: ~/buildSrc/src/main/resources: minimumCompilerVersion、minimumGradleVersion、minimumRuntimeVersion)
- 查看本机JDK版本(7.8.0编译JDK版本最低为14)
二、 导入IDEA (CONTRIBUTING.md)
### Importing the project into IntelliJ IDEA Elasticsearch builds using Java 14. When importing into IntelliJ you will need to define an appropriate SDK. The convention is that **this SDK should be named "14"** so that the project import will detect it automatically. For more details on defining an SDK in IntelliJ please refer to [their documentation](https://www.jetbrains.com/help/idea/sdk.html#define-sdk). SDK definitions are global, so you can add the JDK from any project, or after project import. Importing with a missing JDK will still work, IntelliJ will simply report a problem and will refuse to build until resolved. You can import the Elasticsearch project into IntelliJ IDEA via: - Select **File > Open** - In the subsequent dialog navigate to the root `build.gradle` file - In the subsequent dialog select **Open as Project**
三、 本地运行/调试配置
配置以下JVM参数:
-Des.path.conf=/Users/xuxl/Library/elasticsearch/elasticsearch-7.8.0/config
-Des.path.home=/Users/xuxl/Library/elasticsearch/elasticsearch-7.8.0
-Djava.security.policy=/Users/xuxl/Library/elasticsearch/elasticsearch-7.8.0/config/elasticsearch.policy
-Xms2g
-Xmx2g
-Dlog4j2.disable.jmx=true
-Des.path.plugins=/Users/xuxl/Library/elasticsearch/elasticsearch-7.8.0/plugins
配置 elasticsearch.policy文件(在elasticsearch-home/conf/创建文件),内容如下:
grant{
permission javax.management.MBeanTruxtPermission "register";
permission javax.management.MBeanServerPermission "createMBeanServer";
permission java.lang.RuntimePermission "createClassLoader";
};
源码文件server模块中build.gradle中修改
compileOnly project(':libs:elasticsearch-plugin-classloader') ---》 compile project(':libs:elasticsearch-plugin-classloader')
ps:
需要配置node.name!