Changing JVM for compilation does not work

Hello, i want to compile my code using java 7 while my java_home environment variable points to java 8. I used the following code in my build.gradle but it does not work. Could you please give me hint where is my mistake ?
tasks.withType(JavaCompile) {
options.with {
fork = true
forkOptions.javaHome = file(javaHome)
forkOptions.executable = (javaHome + “\bin\javac”)


I am assuming this is the same as this StackOverflow question and would prefer to keep the conversation in one location.