ElasticSearch构建源码环境步骤:
以版本6.1.2 on mac, idea为例
准备:gradle 4.3版本。jdk10。
jdk10 mac版本可以到我的百度云获取:
链接:https://pan.baidu.com/s/1wEWglWooj0HeyAcVEafdTw 密码:7aet
修改~/.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'
def GRADLE_LOCAL_RELEASE_URL = 'https://repo.gradle.org/gradle/libs-releases-local'
def ALIYUN_SPRING_RELEASE_URL = 'https://maven.aliyun.com/repository/spring-plugin'
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
}
if (url.startsWith('http://repo.spring.io/plugins-release')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_SPRING_RELEASE_URL."
remove repo
}
}
}
maven {
url ALIYUN_REPOSITORY_URL
}
maven {
url ALIYUN_JCENTER_URL
}
maven {
url ALIYUN_SPRING_RELEASE_URL
}
maven {
url GRADLE_LOCAL_RELEASE_URL
}
}
}
1. 修改配置
下载git源码后,终端下cd 到es目录下
执行./gradlew idea
会遇到以下问题
(1)下载地址解析问题,如distribution模块,那么到这个模块下,修改build.gradle,加入以下内容:
buildscript {
repositories {
maven {url "https://plugins.gradle.org/m2/"}
maven {url 'http://maven.aliyun.com/nexus/content/groups/public/' }
maven {url 'http://repo.maven.apache.org/maven2' }
}
dependencies {
classpath 'com.netflix.nebula:gradle-ospackage-plugin:3.4.0'
}
}
如benchmarks模块:
buildscript {
repositories {
maven {url 'https://plugins.gradle.org/m2/' }
maven {url 'http://maven.aliyun.com/nexus/content/groups/public/' }
maven {url 'http://repo.maven.apache.org/maven2' }
}
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.4'
}
}
(2)java_home问题:
将该groovy文件(buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy)
中:
String javaHome = System.getenv('JAVA_HOME')
改为绝对地址路径
String javaHome = "/Library/Java/JavaVirtualMachines/jdk-10.0.2.jdk/Contents/Home"
解决以上问题后再次执行,直到出现则编译成功,如果只需要编译,则到此就可以了。
BUILD SUCCESSFUL in 15s
2. idea环境
idea下编译需要修改gradle配置:
- 选择Use Gradle 'wrapper' task configuration
- JVM配置jdk1.8(idea不兼容问题)
- Service directory path选择:~/.gradle
刷新import,开始build