Reputation: 1277
I have multiple projects and build using Gradle 2.4.
I want to overwrite the org.gradle.java.home
parameter in each project and try to add gradle.properties file for each project and overwrite the parameter.
I have set the main gradle project org.gradle.java.home=C:/Java/jdk1.6.0
and overwrite in subproject as org.gradle.java.home=C:/Java/jdk1.7.0_45
But it is not working as expected and I'm getting
invalid source release: 1.7
error message.
Could someone give idea how to fix this issue?
Upvotes: 14
Views: 18480
Reputation: 2242
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
Upvotes: 6