From my tests:
I have created blank 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's settings.gradle:
include 'sub1'
include 'sub2'
Sub1's gradle.properties:
org.gradle.java.home=/path/to/java8
Sub1's build.gradle:
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
Sub2's gradle.properties:
org.gradle.java.home=/path/to/java7
Sub2's build.gradle:
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
So, you can try this setup.
I guess, because you are using your root project with already defined java (not just as configuration point) - this might be the problem.
Also check these ones:
How do I tell Gradle to use specific JDK version?
Gradle sourceCompatibility has no effect to subprojects