Gradle build 找不到 JAVA_HOME 即使它确实存在
Gradle build not finding JAVA_HOME even when its actually there
我正在尝试构建此项目以开发自定义 x-pack
插件 (https://github.com/elastic/shield-custom-realm-example)
但是,当我尝试在项目根目录中 运行 ./gradlew
时,出现 JAVA_HOME must be set to build Elasticsearch
错误。
以下是我不明白为什么会抛出此错误的详细信息。
➜ shield-custom-realm-example git:(master) echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home
➜ shield-custom-realm-example git:(master) java -version
'java version "10.0.1" 2018-04-17
Java(TM) SE Runtime Environment 18.3 (build 10.0.1+10)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.1+10, mixed mode)
➜ shield-custom-realm-example git:(master) ./gradlew
> Configure project :
Project evaluation failed including an error in afterEvaluate {}. Run with --stacktrace for details of the afterEvaluate {} error.
FAILURE: Build failed with an exception.
* Where:
Build file '~/dev/temp/shield-custom-realm-example/build.gradle' line: 39
* What went wrong:
A problem occurred evaluating root project 'x-pack-custom-realm-extension-example'.
> Failed to apply plugin [id 'elasticsearch.build']
> JAVA_HOME must be set to build Elasticsearch
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.
See https://docs.gradle.org/4.5/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 0s
此外,我还将这些添加到我的 ~/.zshrc
文件中。
export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home"
export RUNTIME_JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home"
尝试 运行 ./gradlew --stop
,使用 env | grep JAVA
确认您的环境变量已导出,然后再次尝试构建。过去发生在我身上 Gradle 守护进程是在没有环境变量的情况下启动的,并且没有重新启动以获取它。
我正在尝试构建此项目以开发自定义 x-pack
插件 (https://github.com/elastic/shield-custom-realm-example)
但是,当我尝试在项目根目录中 运行 ./gradlew
时,出现 JAVA_HOME must be set to build Elasticsearch
错误。
以下是我不明白为什么会抛出此错误的详细信息。
➜ shield-custom-realm-example git:(master) echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home
➜ shield-custom-realm-example git:(master) java -version
'java version "10.0.1" 2018-04-17
Java(TM) SE Runtime Environment 18.3 (build 10.0.1+10)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.1+10, mixed mode)
➜ shield-custom-realm-example git:(master) ./gradlew
> Configure project :
Project evaluation failed including an error in afterEvaluate {}. Run with --stacktrace for details of the afterEvaluate {} error.
FAILURE: Build failed with an exception.
* Where:
Build file '~/dev/temp/shield-custom-realm-example/build.gradle' line: 39
* What went wrong:
A problem occurred evaluating root project 'x-pack-custom-realm-extension-example'.
> Failed to apply plugin [id 'elasticsearch.build']
> JAVA_HOME must be set to build Elasticsearch
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.
See https://docs.gradle.org/4.5/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 0s
此外,我还将这些添加到我的 ~/.zshrc
文件中。
export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home"
export RUNTIME_JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home"
尝试 运行 ./gradlew --stop
,使用 env | grep JAVA
确认您的环境变量已导出,然后再次尝试构建。过去发生在我身上 Gradle 守护进程是在没有环境变量的情况下启动的,并且没有重新启动以获取它。