sam
sam

Reputation: 491

Gradle gets wrong value for JAVA_HOME in mac

When trying to build an android application from Jenkins using gradle, I get the following error:

ERROR: JAVA_HOME is set to an invalid directory: /usr/lib/jvm/java-8-oracle
Please set the JAVA_HOME variable in your environment to match the location of your Java installation.

Build step 'Invoke Gradle script' changed build result to FAILURE
Build step 'Invoke Gradle script' marked build as failure
Finished: FAILURE

However, when I check the JAVA_HOME variable I get:

Macs-Mac-mini:~ mac$ echo $JAVA_HOME 
/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home

Running java -version.

Macs-Mac-mini:~ mac$ java -version 
java version "1.8.0_112"
Java(TM) SE Runtime Environment (build 1.8.0_112-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.112-b16, mixed mode)

why does Gradle find /usr/lib/jvm/java-8-oracle

tried Gradle finds wrong JAVA_HOME and Gradle does not recognize the JAVA_HOME

Upvotes: 1

Views: 1746

Answers (2)

sam
sam

Reputation: 491

After lot of debugging i found that, Gradle was taking $JAVA_HOME variable value from Jenkins master JDK configuration not from node's $JAVA_HOME variable.

I removed default JDK configuration path from Jenkins master and Gradle took $JAVA_HOME variable value from node.

Upvotes: 3

dwursteisen
dwursteisen

Reputation: 11515

You're not logged as a Jenkins user, so echo $JAVA_HOME only display the JAVA_HOME of the current user, which may not the same as Jenkins user.

Fortunately, you can set an environnement variable from the Jenkins user interface. (see this example, just replace JMETER_HOME with JAVA_HOME)

Upvotes: 0

Related Questions