Scala compiler is unable to find a javac compiler under Mac OS with Java 1.7, gradle 1.1

Hello, I’m currently running into a strange problem with Java 1.7 under Mac OS.

I have set the JDK 1.7 path in my file like this:


org.gradle.jvmargs=-Xmx1g -XX:MaxPermSize=128m

When I run a full build for my scala project, I get

FAILURE: Build failed with an exception.

  • What went wrong:

Execution failed for task ‘:compileScala’.

Unable to find a javac compiler; is not on the classpath.

Perhaps JAVA_HOME does not point to the JDK.

It is currently set to “/Library/Java/JavaVirtualMachines/jdk1.7.0_07.jdk/Contents/Home/jre”

  • Try:

Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.


(Note aside: this happens because there are also java sources in the scala source path. If there are only scala source files, everything is fine)

So the question is: why is gradle using the JRE and not the JDK path (since points to the JDK)

I have no JAVA_HOME set. The java command on the path, is a java 1.6.

However, after setting

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_07.jdk/Contents/Home

the problem is gone.

Nevertheless I would expect that providing

should be enough.

Cheers, Oliver

In all likelihood, Gradle is using the JDK (you can check with ‘println System.getProperty(“java.version”)’ in the build script). It’s the Scala compiler that doesn’t find ‘javac’. Apparently the Scala compiler expects the ‘JAVA_HOME’ environment variable to be set, and apparently setting ‘’ doesn’t also set the environment variable. Maybe it should.

The other question is whether the Scala compiler supports the official JDK6 compiler API (instead of the proprietary JDK5 ‘’), which it should find on the class path. From the error message, it sounds like it doesn’t support it (and it definitely should). It might be worthwhile to raise this on the Scala list.

What does this print?

task debug << {
  println System.getProperty("java.home")

Without JAVA_HOME and set it prints


which is ok and everything works fine.

Having set to /Library/Java/JavaVirtualMachines/jdk1.7.0_07.jdk/Contents/Home and still no JAVA_HOME the output is


which does not work (because of the jre).

Setting JAVA_HOME to the same path as doesn’t change the output (still …/Home/jre), however, now the scala compiler is able to find javac.

I think our JDK detection logic goes wrong in that case because it’s a Mac but nevertheless has the Oracle JDK directory layout rather than the Apple JDK layout. I’ve raised GRADLE-2460 for this.

It looks like the Scala compiler falls back to the ‘java.home’ system property in case the ‘JAVA_HOME’ environment variable is absent. However, ‘java.home’ always points to a JRE rather than a JDK (this is the expected behavior). What I don’t understand is why the Scala compiler doesn’t find ‘’ on the class path.

That said, I’m not able to reproduce your problem (I’ve tried with ‘samples/scala/mixedJavaAndScala’ from the full Gradle distribution). Can you provide a reproducible example? Also, which Scala version are you on?

Probably not the smallest, but for the moment the quickest self-containing example: Download and run gradle. (And don’t forget to provide a ‘’ in your own ‘~/.gradle/’) We’re using Scala 2.9.2.


I’ve just detected that I had set an environment variable JAVA_VERSION=1.6

When I unset this variable or alternatively set it to 1.7 everything works fine.

Only with the value 1.6 the problem above occurs.

Unsure what this means as I can reproduce the problem without having JAVA_VERSION set.