Closed igr closed 9 years ago
I see that property is set:
project.properties.each {println " $it"}
however, it is not applied to the project; I am not able to compile project with different JDK?
Short answer: Gradle itself doesn't notice changes to the org.gradle.java.home
property once set. As a wourkaround, you will need to either specify the JDK in one of Gradle's standard property files, or add -Dorg.gradle.java.home=/path/to/jdk
to the command line when you are building in an environment where a different JDK is desired.
In order to fix this, you'd need to report a bug against Gradle itself to allow you to change the JDK used inside your build.gradle
script itself.
If you are needing help falling asleep, here is a longer explanation :-)
When Gradle starts up, it reads the project's gradle.properties
file, the user's gradle.properties
file, system properties, and any properties set on the command line with -D
arguments. It initializes project properties and does other internal things all prior to reading your build.gradle
file or applying any plugins. When you apply the properties plugin, it re-reads these files, but adds some additional files to the mix (like gradle-local.properties
), giving you greater control over how properties get set, but it can't do much about decisions that Gradle has already made up to that point, which appears to be what is causing this particular issue. It looks like Gradle decides what JDK to use before it starts processing your build.gradle
file, and doesn't let you change it afterwords.
To prove this, I tried the following test:
project.ext."org.gradle.java.home"="/opt/jdk1.7.0_09"
to my build.gradle file. This sets the property completely outside of the properties plugin. You could set up a simple project that doesn't even use the properties plugin, and you'd get the same result.gradle properties
and saw that the org.gradle.java.home
property was indeed set.gradle compileJava
and watched as my newly specified JDK was completely ignored.Thank you!
I don't know what I am doing wrong, but I am not able to set custom
org.gradle.java.home
ingradle-local.properties
. When I run gradle in debug mode, I see that 1 property is loaded fromgradle-local.properties
(the local jdk path), however, this value is simply ignored.