Elasticsearch V5.0.1 源码在Idea中如何运行
1. 下载源码
github: 传送门
2. 安装gradle
这里只说注意事项,具体安装请自行百度
必须是2.13版本才行,2.13的下载地址:
官方下载地址
腾讯微云下载地址
否则会报以下错误:
Gradle 2.13 is required to build elasticsearch
# 这个报错可注释掉elasticsearch/buildSrc/build.gradle中32行左右的代码:
if (GradleVersion.current() != GradleVersion.version('2.13')) {
throw new GradleException('Gradle 2.13 is required to build elasticsearch')
}
# 然而,虽然上面的报错可以通过注释代码解决,但是这个报错,我们却无能为力,只有准确的使用2.13版本才能解决
# https://github.com/elastic/elasticsearch/issues/18935
# https://discuss.gradle.org/t/gradle-2-14-breaks-plugins-using-consolerenderer/18045
Generating JAR file 'gradle-api-3.2.1.jar'
:buildSrc:clean
:buildSrc:compileJava
:buildSrc:compileGroovy
startup failed:
/Users/ervin/IdeaProjects/sourceCode/elasticsearch/buildSrc/src/main/groovy/com/carrotsearch/gradle/junit4/TestProgressLogger.groovy: 28: unable to resolve class org.gradle.logging.ProgressLogger
@ line 28, column 1.
import org.gradle.logging.ProgressLogger
^
/Users/ervin/IdeaProjects/sourceCode/elasticsearch/buildSrc/src/main/groovy/org/elasticsearch/gradle/vagrant/TapLoggerOutputStream.groovy: 25: unable to resolve class org.gradle.logging.ProgressLogger
@ line 25, column 1.
import org.gradle.logging.ProgressLogger
^
/Users/ervin/IdeaProjects/sourceCode/elasticsearch/buildSrc/src/main/groovy/org/elasticsearch/gradle/vagrant/VagrantLoggerOutputStream.groovy: 23: unable to resolve class org.gradle.logging.ProgressLogger
@ line 23, column 1.
import org.gradle.logging.ProgressLogger
^
3 errors
:buildSrc:compileGroovy FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileGroovy'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
3. 更改gradle的远程仓库
gradle的仓库需求翻墙才能下载依赖。但是好在gradle可以使用maven仓库,如下:
repositories {
maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'}
}
> 开源中国的仓库貌似已经废弃了,阿里云的倒是不错的选择,如上。
**更改gradle仓库的步骤**
* 将es源码中所有的显式指定仓库的地方都换为阿里云的仓库地址
repositories {
maven {
url 'https://plugins.gradle.org/m2/'
}
}
repositories {
jcenter()
}
* 然后,将下面这段Copy到名为init.gradle文件中,并保存到 USER_HOME/.gradle/文件夹下即可。
allprojects{
repositories {
def REPOSITORY_URL = 'http://maven.aliyun.com/nexus/content/groups/public/'
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
}
}
}
maven {
url REPOSITORY_URL
}
}
}
> init.gradle文件其实是Gradle的初始化脚本(Initialization Scripts),也是运行时的全局配置。
更详细的介绍请参阅 http://gradle.org/docs/current/userguide/init_scripts.html
## 4.在elasticsearch源码根目录下,在命令行中运行gradle idea
## 5.将elasticsearch源码导入idea工程
具体导入方式参看博客:http://www.cnblogs.com/yjmyzz/p/gradle-getting-start.html