Java Programming Tutorials

Java programming tutorials with many code examples!

Gradle Java version


How to set Java source and target versions in Gradle build?


Java Plugin for Gradle has two properties for handling Java source and target versions:

  • sourceCompatibility
  • targetCompatibility

By default Gradle will use version of the current JDK for sourceCompatibility and will use value of sourceCompatibility as targetCompatibility. So in case of the same source and target values it’s enough to set only sourceCompatibility.

Here’s sample Gradle configuration, where set Java source version to 1.7 and compiled code (target) to 1.8:

// Enable Java project settings:
apply plugin: 'java'
// Source and target are exposed by the Java plugin
// and are passed to the Java compiler:
sourceCompatibility = 1.7
targetCompatibility = 1.8
Was it helpful? Share!