Skip to content

Gradle JAVA_HOME Issue Resolution

breznak edited this page Sep 2, 2015 · 2 revisions

Some users are having issues with Gradle on Linux ignoring the "JAVA_HOME" environment setting, and report that Gradle points to a different Java installation than the default one on their system, namely:

Summary of problems:

  • gradle picked up JVM other than 1.8 (fix default-java symlink)
  • gradle version too old (update gradle from PPA)

Gradle JAVA_HOME problem

A user found the following solution: See this for further reference


 update-alternatives --config java
There are 3 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                            Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-8-oracle/jre/bin/java          1076      auto mode
  1            /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java   1061      manual mode
  2            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1071      manual mode
  3            /usr/lib/jvm/java-8-oracle/jre/bin/java          1076      manual mode

But somehow "default-java" was pointing elsewhere:

$ ls /usr/lib/jvm -l
total 16
lrwxrwxrwx 1 root root   24 Apr 27  2012 default-java -> java-1.7.0-openjdk-amd64
lrwxrwxrwx 1 root root   20 Apr 16  2014 java-1.6.0-openjdk-amd64 -> java-6-openjdk-amd64
lrwxrwxrwx 1 root root   20 Oct 25  2012 java-1.7.0-openjdk-amd64 -> java-7-openjdk-amd64
drwxr-xr-x 7 root root 4096 Aug  6 21:21 java-6-openjdk-amd64
drwxr-xr-x 3 root root 4096 May  9  2014 java-6-openjdk-common
drwxr-xr-x 7 root root 4096 Aug  3 15:18 java-7-openjdk-amd64
drwxr-xr-x 8 root root 4096 Aug 24 15:33 java-8-oracle

manually fixing the symlink makes gradle pick up JVM 1.8 correctly:

$ gradle --version

------------------------------------------------------------
Gradle 1.4
------------------------------------------------------------

Gradle build time: Monday, September 9, 2013 8:44:25 PM UTC
Groovy: 1.8.6
Ant: Apache Ant(TM) version 1.9.3 compiled on April 8 2014
Ivy: non official version
JVM: 1.8.0_60 (Oracle Corporation 25.60-b23)
OS: Linux 3.13.0-63-generic amd64

Gradle too old (no support for jcenter())

Which moves me to another error:

$ gradle check

FAILURE: Build failed with an exception.

* Where:
Build file '/home/mmm/devel/nupic/htm.java/build.gradle' line: 51

* What went wrong:
A problem occurred evaluating root project 'htm.java'.
> Could not find method jcenter() for arguments [] on repository container.

For which I found: https://stackoverflow.com/questions/27470443/could-not-find-method-jcenter-for-arguments-on-repository-container

Fix: Install a newer Gradle from PPA

sudo add-apt-repository ppa:cwchien/gradle
sudo apt-get update
sudo apt-get install gradle