[GRADLE-2460] Scala compiler is unable to find a javac compiler under Mac OS with Java 1.7, gradle 1.1 Created: 02/Sep/12  Updated: 04/Jan/13  Resolved: 17/Oct/12

Status: Resolved
Project: Gradle
Affects Version/s: None
Fix Version/s: 1.3-rc-1

Type: Bug
Reporter: Gradle Forums Assignee: Peter Niederwieser
Resolution: Fixed Votes: 0


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 gradle.properties 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;
    com.sun.tools.javac.Main 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 gradle.properties 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.


Comment by Gradle Forums [ 02/Sep/12 ]

What does this print?

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

Comment by Gradle Forums [ 02/Sep/12 ]

Without JAVA_HOME and org.gradle.java.home set it prints


which is ok and everything works fine.

Having org.gradle.java.home 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 org.gradle.java.home doesn't change the output (still ..../Home/jre), however, now the scala compiler is able to find javac.

Comment by Peter Niederwieser [ 07/Sep/12 ]

This turned out to be a much more generic issue where system properties like os.name and os.version were carried over from the client JVM to the daemon JVM. If the daemon JVM was running with a different JDK due to org.gradle.java.home being set, this could lead do wrong decision being made on the daemon/build side. In the concrete case, tools.jar wasn't added to the daemon Oracle JVM because the client JVM was Apple (which was carried over). Hence com.sun.tools.javac.Main wasn't available in the daemon JVM.

Comment by Mauro Molinari [ 17/Oct/12 ]

The root cause seemed to also have the consequence outlined here: http://forums.gradle.org/gradle/topics/relationship_between_the_java_runtime_used_to_run_the_tooling_api_and_the_java_home

The fix version is 1.3, isn't it?

Generated at Wed Jun 30 12:22:31 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.