# Cannot Build Using Gradle; JAVA\_HOME Not found

**URL:** <https://discuss.elastic.co/t/cannot-build-using-gradle-java-home-not-found/131062>\
**Category:** Elasticsearch\
**Created:** [May 8, 2018, 8:41pm UTC](https://discuss.elastic.co/t/cannot-build-using-gradle-java-home-not-found/131062 "2018-05-08T20:41:37Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![\_mni](https://avatars.discourse-cdn.com/v4/letter/_/ecb155/32.png) [@\_mni](https://discuss.elastic.co/u/_mni)\
**Post date:** [May 8, 2018, 8:41pm UTC](https://discuss.elastic.co/t/cannot-build-using-gradle-java-home-not-found/131062/1 "2018-05-08T20:41:38Z")

</div>

I am trying to build on the custom-realm-example as published on github. However, no matter what I do I am unable to build the project. Here's some details on what's going on:

```
➜ 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
➜ shield-custom-realm-example git:(master)
```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [May 8, 2018, 9:06pm UTC](https://discuss.elastic.co/t/cannot-build-using-gradle-java-home-not-found/131062/2 "2018-05-08T21:06:50Z")

</div>

> JAVA\_HOME must be set to build Elasticsearch

---

<div class="post-metadata">

**Author:** ![\_mni](https://avatars.discourse-cdn.com/v4/letter/_/ecb155/32.png) [@\_mni](https://discuss.elastic.co/u/_mni)\
**Post date:** [May 8, 2018, 9:21pm UTC](https://discuss.elastic.co/t/cannot-build-using-gradle-java-home-not-found/131062/3 "2018-05-08T21:21:29Z")

</div>

That's why I had this shown in the above logs.

```
shield-custom-realm-example git:(master) echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home
```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [May 8, 2018, 9:33pm UTC](https://discuss.elastic.co/t/cannot-build-using-gradle-java-home-not-found/131062/4 "2018-05-08T21:33:14Z")

</div>

Can you try with Java8 or Java9?

---

<div class="post-metadata">

**Author:** ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)\
**Post date:** [May 9, 2018, 12:30am UTC](https://discuss.elastic.co/t/cannot-build-using-gradle-java-home-not-found/131062/5 "2018-05-09T00:30:06Z")

</div>

Do you have the gradle daemon enabled? Try running `./gradlew --stop` and then running your build again. Also, is your JAVA\_HOME variable exported?

---

<div class="post-metadata">

**Author:** ![\_mni](https://avatars.discourse-cdn.com/v4/letter/_/ecb155/32.png) [@\_mni](https://discuss.elastic.co/u/_mni)\
**Post date:** [May 9, 2018, 3:14am UTC](https://discuss.elastic.co/t/cannot-build-using-gradle-java-home-not-found/131062/6 "2018-05-09T03:14:21Z")

</div>

@dadoonet I could not find a site that would allow me download java9 JDK, seems like oracle has removed it? I cant use JDK8 to build elasticsearch 6 plugins

@rjernst Please look at the first two lines in the logs I posted above. I have echoed the $JAVA\_HOME variable, is there more than that to it?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [May 9, 2018, 3:53am UTC](https://discuss.elastic.co/t/cannot-build-using-gradle-java-home-not-found/131062/7 "2018-05-09T03:53:04Z")

</div>

I'm using sdkman to switch from one jvm to another. Give it a try may be?

---

<div class="post-metadata">

**Author:** ![TimV](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/timv/32/13162_2.png) [@TimV](https://discuss.elastic.co/u/TimV)\
**Post date:** [May 9, 2018, 4:12am UTC](https://discuss.elastic.co/t/cannot-build-using-gradle-java-home-not-found/131062/8 "2018-05-09T04:12:36Z")

</div>

> [@\_mni](#):
>
> I have echoed the $JAVA\_HOME variable, is there more than that to it?

@rjernst asked if the JAVA\_HOME is exported. That is different to simply setting the variable.

If you want the variable to be available to a child process (which you do) then you need to

```auto
export JAVA_HOME

```

---

<div class="post-metadata">

**Author:** ![zqc0512](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zqc0512/32/32141_2.png) [@zqc0512](https://discuss.elastic.co/u/zqc0512)\
**Post date:** [May 9, 2018, 6:55am UTC](https://discuss.elastic.co/t/cannot-build-using-gradle-java-home-not-found/131062/9 "2018-05-09T06:55:43Z")

</div>

before build export JAVA\_HOME with you correct java

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 6, 2018, 6:55am UTC](https://discuss.elastic.co/t/cannot-build-using-gradle-java-home-not-found/131062/10 "2018-06-06T06:55:45Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
