I can\'t figure out to get this working.
Scenario:
What I w
If you just want to set it once to run a specific command:
JAVA_HOME=/usr/lib/jvm/java-11-oracle/ gw build
So, I use IntelliJ for my Android project, and the following solved the issue in the IDE:
just cause it might save someone the few hours I wasted... IntelliJ -> Preferences -> Build, Execution, Deployment -> Build tools -> Maven -> Gradle
and set Gradle JVM to 1.8 make sure you also have JDK 8 installed...
NOTE: the project was compiling just fine from the command line
If you are using linux and gradle wrapper you can use following solution.
Add path to local.properties file:
javaHome=<path to JDK>
Add to your gradlew script file:
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
source $DIR/local.properties 2>/dev/null
if ! [ -z "$javaHome" ]
then
JAVA_HOME=$javaHome
fi
In this solution, each developer can set his own JDK path. File local.properties
shouldn't be included in version control system.
there is a Gradle plugin that download/bootstraps a JDK automatically:
https://plugins.gradle.org/plugin/com.github.rmee.jdk-bootstrap
No IDE integration yet and a decent shell required on Windows.
File > Project Structure > SDK Location > JDK Location >
/usr/lib/jvm/java-8-openjdk-amd64
GL
Install JDK
To people ending up here when searching for the Gradle equivalent of the Maven property maven.compiler.source
(or <source>1.8</source>
):
In build.gradle you can achieve this with
apply plugin: 'java'
sourceCompatibility = 1.8
targetCompatibility = 1.8
See the Gradle documentation on this.