Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gradle idea incorrectly fails with JAVA_HOME not set #31399

Closed
alpar-t opened this issue Jun 18, 2018 · 6 comments · Fixed by #32022
Closed

gradle idea incorrectly fails with JAVA_HOME not set #31399

alpar-t opened this issue Jun 18, 2018 · 6 comments · Fixed by #32022
Assignees
Labels
:Delivery/Build Build or test infrastructure Team:Delivery Meta label for Delivery team

Comments

@alpar-t
Copy link
Contributor

alpar-t commented Jun 18, 2018

user @doubleuhy notes that:

gradle idea

Where:
Build file '/Users/zhouwuhong/elasticsearch/benchmarks/build.gradle' line: 31

What went wrong:
A problem occurred evaluating project ':benchmarks'.

Failed to apply plugin [id 'elasticsearch.build']
JAVA_HOME must be set to build Elasticsearch

but

echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk-10.jdk/Contents/Home

I have seen this in the past, including on SO. I think what happens is that importing the project from idea without running ./gradlew idea first creates a daemon that is not restarted when running ./gradlew idea from the command line with the env var set despite there being a different env.

Running ./gradlew --stop makes the problem go away.

@alpar-t alpar-t added the :Delivery/Build Build or test infrastructure label Jun 18, 2018
@alpar-t alpar-t self-assigned this Jun 18, 2018
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra

This was referenced Jun 18, 2018
@alpar-t
Copy link
Contributor Author

alpar-t commented Jul 9, 2018

just saw this in the Gradle dameon log:

09:33:08.432 [WARN] [org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment] Warning: Unable able to set daemon's environment variables to match the client because:
  Java 9 does not support modifying environment variables.
  If the daemon was started with a significantly different environment from the client, and your build
  relies on environment variables, you may experience unexpected behavior.

Which comes from gradle/gradle#2159

@alpar-t
Copy link
Contributor Author

alpar-t commented Jul 9, 2018

I don't think that there's much we can do about that.
I really think Gradle shouldn't be so silent about this, and start a new daemon.
The best we can do is to update the error message we throw when no JAVA_HOME is set to have a note about this behavior, maybe link to this issue.

@alpar-t
Copy link
Contributor Author

alpar-t commented Jul 13, 2018

@rjernst, why are we requiring the env var in the first place? Is it because we run stuff as part of the tests that require it ? Would it be better to pass it explicitly in these cases ?

alpar-t added a commit to alpar-t/elasticsearch that referenced this issue Jul 13, 2018
@rjernst
Copy link
Member

rjernst commented Jul 13, 2018

There are a couple of reasons we require JAVA_HOME:

  • Ensures the user is explicitly telling us which java to build with. We've had many problems in the past where a contributor was using a different version of java than they realized because one was on the PATH earlier than another.
  • Makes it easier to quickly switch between java versions by setting the env var, instead of changing PATH. This was more important before we could trust --release in java to compile against a different version specification/libs.

@tarzanek
Copy link

tarzanek commented Nov 9, 2020

for ElasticSearch 6.8.4
you need to set and export also variable JAVA12_HOME
and probably others,
see https://github.com/elastic/elasticsearch/blob/master/CONTRIBUTING.md#contributing-to-the-elasticsearch-codebase

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Delivery/Build Build or test infrastructure Team:Delivery Meta label for Delivery team
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants