From my tests:
I created an empty root project without specifying which java to use and included two subprojects with different org.gradle.java.home and sourceCompatibility and targetCompatibility for each subproject and it works.
Project Structure :
/build.gradle <-- root project (no sourceCompatibility or targetCompatibility here .. just blank) /settings.gradle <-- include the subprojects /gradle.properties <-- root gradle.properties (no org.gradle.java.home here) /sub1/build.gradle /sub1/gradle.properties /sub2/build.gradle /sub2/gradle.properties
Root settings .gradle :
include 'sub1' include 'sub2'
Sub1 gradle.properties :
org.gradle.java.home=/path/to/java8
Sub1 build.gradle :
sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8
Sub2 gradle.properties :
org.gradle.java.home=/path/to/java7
Sub2 build.gradle :
sourceCompatibility = JavaVersion.VERSION_1_7 targetCompatibility = JavaVersion.VERSION_1_7
So you can try this setting.
I assume because you are using your root project with java already defined (and not just a configuration point) - this could be a problem.
Also check these:
How do I tell Gradle to use a specific version of the JDK?
Gradle sourceCompatibility does not affect subprojects
source share