13

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?

user3496599
  • 1,207
  • 2
  • 12
  • 28
  • 1
    Are you wanting to run a different version of gradle for different projects? If so, you should be making use of the Gradle Wrapper – tddmonkey Jun 01 '15 at 10:33
  • @MrWiggles I'm trying to use different java versions not different version of gradle. – user3496599 Jun 01 '15 at 10:41
  • 2
    You mean you have a multi-module build and you want a different version of java for child modules? I believe you should use the highest version of the JDK you need and just set sourceCompatibility and targetCompatibility for each module – tddmonkey Jun 01 '15 at 10:44
  • @MrWiggles Can't I overwrite the 'org.gradle.java.home' in gradle.properties file? My requirement is that. May I know is it possible or not? – user3496599 Jun 01 '15 at 10:54
  • Not as far as I'm aware as the gradle process has already spun up - what is it you're trying to achieve by doing this? – tddmonkey Jun 02 '15 at 09:36

1 Answers1

5

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

Community
  • 1
  • 1
Danail
  • 1,997
  • 18
  • 21