Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How specify the required Java version in a Gradle build

Tags:

java

gradle

I would like to set in a Gradle build file the required Java version e.g. 7 or 8 without having to specify the actual path to a local JDK installation.

Is this possible ?

like image 598
pditommaso Avatar asked Jan 09 '15 13:01

pditommaso


People also ask

How do I set Java version in build Gradle?

Set the JDK version Open your project in Android Studio and select File > Settings... > Build, Execution, Deployment > Build Tools > Gradle (Android Studio > Preferences... > Build, Execution, Deployment > Build Tools > Gradle on a Mac). Under Gradle JDK, choose the Embedded JDK option.

What Java version does Gradle use?

Gradle can only run on Java version 8 or higher. Gradle still supports compiling, testing, generating Javadoc and executing applications for Java 6 and Java 7. Java 5 and below are not supported.

How do I specify the Gradle version?

You can specify the Gradle version in either the File > Project Structure > Project menu in Android Studio, or update your Gradle version using the command line.

How do I change the Java version in Gradle settings dialog?

Access the Gradle JVM settingsIn the Settings/Preferences dialog ( Ctrl+Alt+S ), select Build, Execution, Deployment | Build Tools | Gradle. On the Gradle settings page, under the Gradle section, use the Gradle JVM option to check the Gradle version used for importing a project.


1 Answers

TLDR; Thanks @franklin-yu "targetCompatibility = '1.7' -> your user can compile with 8 and run with 7."

See Gradle, "sourceCompatibility" vs "targetCompatibility"?

targetCompatibility = '1.7' does the trick for e.g. Java 7

Use sourceCompatibility = '1.7' for the language level

like image 140
dhfsk Avatar answered Sep 25 '22 13:09

dhfsk