MAC: Gradle issues with finding/using JDK 7 - the usual answers to this question aren't working. Expert required

This issue appears to be related directly to a bizarre gradle/osx interaction, rather than the IDEs using Gradle.

In Android Studio and Eclipse I am having issues with the gradle-build bombing out with errors that the web tells me are related to the JDK. Android studio works with the Apple provided JDK1.6, but when I install Oracle JDK1.7, which is required for the projects I am doing, it bombs

Error:Execution failed for task ‘:app:compileDebugJava’. > Cannot find System Java Compiler. Ensure that you have installed a JDK (not just a JRE) and configured your JAVA_HOME system variable to point to the according directory.

On my other mac, I dont have any problems. The setup is the same as far as I can tell. Its just that for some reason, on one machine, Android Studio / Gradle pops this error message.

In Android Studio I have set file->other settings->default project settings-> JDK location to the JDK location listed below in JAVA_HOME.

I have set

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

running /usr/libexec/java_home

gives:

/Library/Java/JavaVirtualMachines/jdk1.7.0_60.jdk/Contents/Home

running javac -version

gives :

javac 1.7.0_60-ea

running java -version

gives: java version “1.7.0_60-ea” Java™ SE Runtime Environment (build 1.7.0_60-ea-b15) Java HotSpot™ 64-Bit Server VM (build 24.60-b09, mixed mode)

I have even manually set the symlink CurrentJDK to the 1.7JDK as I have seen that offered as a solution a few times - no luck.

SIMILARLY, in ECLIPSE when running a different (libgdx) gradle-based project, the build process fails with this error:

com/github/jtakakura/gradle/plugins/robovm/RoboVMPlugin : Unsupported major.minor version 51.0

Which posts like this one say is also related to the JDK1.7 being required.

WHY DOES MY ENTIRE SYSTEM EXCEPT AGREE THAT JDK1.7 IS BEING USED, EXCEPT FOR GRADLE?!?!?!

ps: I am running Android Studio at work and have installed jdk1.7 and I have no issues. Almost certainly this is some bizarre interaction between gradle and this particular mac setup - some obscure OSX/java related issue about how Gradle finds the compiler or something…. But I have no clue

mac/gradle experts…help please!

https://github.com/libgdx/libgdx/issues/1603

This link explains that the eclipse problem I am having above is also related to the JDK1.7 not being found by gradle, even though it has been explicitly pointed to that JDK both in the libgdx project setup and in the eclipse preferences.

I dunno that it matters, but you can try changing your JAVA_HOME. Oracle recommends

# see http://docs.oracle.com/javase/7/docs/webnotes/install/mac/mac-jdk.html  export JAVA_HOME='/usr/libexec/java_home -v 1.7'  PATH=$JAVA_HOME/bin:$PATH  

I have this set in my ~/.bash_profile and have no problems with Eclipse or Gradle.

Is the Gradle server process running that was launched with an earlier value for JAVA_HOME? gradle --stop just to be sure.

Do you have anything odd set for the GRADLE_OPTS environment variable?

You mention this is an “eclipse” problem… For applications that are NOT launched from a command line you need to set JAVA_HOME with launchd. Edit /etc/launchd.conf (create it if it doesn’t exist) and add the following line:

setenv JAVA_HOME /Library/Java/JavaVirtualMachines/jdk1.7.0_60.jdk/Contents/Home

Reboot.

Thanks, but neither of these options solves the issue.

Gradle was installed by Android studio (a variant of IntelliJ for Android devlopment) There also must have been a version installed by the libgdx project builder which uses gradle.

is there a way to interrogate Gradle to find out what it thinks is going on?

I guess first I have to find out where these IDEs have put it, as it isnt in my path by default.

ARRGH!

Just for kicks, I installed the same jdk on my kids clunkly old macbook, and installed android studio on it, and run the default project, and it worked fine. Just as it did on the mac at work.

Didnt have to set JAVA_HOME or any maklarkey at all, it just worked.

Its only my own personal machine that must have some arcane setting on it somehow that is fooling gradle.

Ive uninstalled the jdk, uninstalled android studio, reinstalled the official JDK1.6 from apple, just to get a clean start, and reinstalled the jdk1.7 and android studio again, and the identical process just refuses to work. somehow the whatever it is that is fooling gradle is not cleaned up by doing that.

any mac experts out there?

cheers

And after a lot of installing, I can confirm that the libgdx/eclipse project also works on the other computer.

I dont know if anyone is still reading this. but I tried installing standalone gradle and building the project from the commadn line - it still fails, but I can get more info.

You can see that it is hitting up JDK1.6 even though , as described above, everything else in the world points to JDK1.7

HOW IS GRADLE DETERMINING THE JDK TO USE??!?!??

laptop-2:MyApplication2 stef$ gradle --stacktrace build :app:preBuild :app:compileDebugNdk UP-TO-DATE :app:preDebugBuild :app:checkDebugManifest :app:prepareDebugDependencies :app:compileDebugAidl UP-TO-DATE :app:compileDebugRenderscript UP-TO-DATE :app:generateDebugBuildConfig UP-TO-DATE :app:generateDebugAssets UP-TO-DATE :app:mergeDebugAssets UP-TO-DATE :app:generateDebugResValues UP-TO-DATE :app:generateDebugResources UP-TO-DATE :app:mergeDebugResources UP-TO-DATE :app:processDebugManifest UP-TO-DATE :app:processDebugResources UP-TO-DATE :app:generateDebugSources UP-TO-DATE :app:compileDebugJava FAILED

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ‘:app:compileDebugJava’. > Cannot find System Java Compiler. Ensure that you have installed a JDK (not just a JRE) and configured your JAVA_HOME system variable to point to the according directory.

  • Try: Run with --info or --debug option to get more log output.

  • Exception is: org.gradle.api.tasks.TaskExecutionException: Execution failed for task ‘:app:compileDebugJava’.

at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)

at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)

at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)

at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64)

at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)

at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:42)

at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)

at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)

at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)

at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:289)

at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.executeTask(AbstractTaskPlanExecutor.java:79)

at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:63)

at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:51)

at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:23)

at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:86)

at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:29)

at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)

at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23)

at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:67)

at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)

at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)

at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:54)

at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:166)

at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:113)

at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:81)

at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:64)

at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:33)

at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:24)

at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:35)

at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)

at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:50)

at org.gradle.internal.Actions$RunnableActionAdapter.execute(Actions.java:171)

at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:201)

at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:174)

at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:170)

at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:139)

at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)

at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)

at org.gradle.launcher.Main.doAction(Main.java:46)

at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)

at org.gradle.launcher.Main.main(Main.java:37)

at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:50)

at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:32)

at org.gradle.launcher.GradleMain.main(GradleMain.java:23) Caused by: java.lang.RuntimeException: Cannot find System Java Compiler. Ensure that you have installed a JDK (not just a JRE) and configured your JAVA_HOME system variable to point to the according directory.

at org.gradle.api.internal.tasks.compile.jdk6.Jdk6JavaCompiler.createCompileTask(Jdk6JavaCompiler.java:57)

at org.gradle.api.internal.tasks.compile.jdk6.Jdk6JavaCompiler.execute(Jdk6JavaCompiler.java:44)

at org.gradle.api.internal.tasks.compile.jdk6.Jdk6JavaCompiler.execute(Jdk6JavaCompiler.java:38)

at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.delegateAndHandleErrors(NormalizingJavaCompiler.java:96)

at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.execute(NormalizingJavaCompiler.java:49)

at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.execute(NormalizingJavaCompiler.java:35)

at org.gradle.api.internal.tasks.compile.DelegatingJavaCompiler.execute(DelegatingJavaCompiler.java:29)

at org.gradle.api.internal.tasks.compile.DelegatingJavaCompiler.execute(DelegatingJavaCompiler.java:20)

at org.gradle.api.internal.tasks.compile.CleaningJavaCompilerSupport.execute(CleaningJavaCompilerSupport.java:33)

at org.gradle.api.internal.tasks.compile.CleaningJavaCompilerSupport.execute(CleaningJavaCompilerSupport.java:24)

at org.gradle.api.tasks.compile.Compile.performCompilation(Compile.java:165)

at org.gradle.api.tasks.compile.Compile.compile(Compile.java:153)

at org.gradle.api.tasks.compile.Compile.compile(Compile.java:87)

at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:63)

at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$IncrementalTaskAction.doExecute(AnnotationProcessingTaskFactory.java:236)

at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:212)

at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$IncrementalTaskAction.execute(AnnotationProcessingTaskFactory.java:223)

at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:201)

at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:533)

at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:516)

at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)

at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)

… 43 more

BUILD FAILED

“Ensure that you have installed a JDK (not just a JRE) and configured your JAVA_HOME system variable to point to the according directory.”

And you confirmed in the same shell that JAVA_HOME was set as you expected and the directory it was set to exists, etc.?

You wrote earlier: “I have even manually set the symlink CurrentJDK to the 1.7JDK as I have seen that offered as a solution a few times”

Everything I have read indicates this is a “bad idea”. I wonder if the system is messed up because you tried this and now it just isn’t working properly even when you have JAVA_HOME set correctly.

I see another users posted: PATH=$JAVA_HOME/bin:$PATH

You don’t need to do that. Java is on the path already and will magically select the right version based on JAVA_HOME.

Try this, see where it differs from what I get:

$ which java /usr/bin/java

$ echo $JAVA_HOME /Library/Java/JavaVirtualMachines/jdk1.7.0_60.jdk/Contents/Home

$ java -version java version “1.7.0_60” …

$ gradle --version … JVM:

1.7.0_60…

$ export JAVA_HOME=’/usr/libexec/java_home -v1.8’ $ which java /usr/bin/java $ java -version java version “1.8.0_20-ea” …

$ gradle --version … JVM:

1.8.0_20-ea…

Thanks for your reply…

results shown below.

I do know from experimentation that JAVA_HOME doesnt have to be set for gradle to work, because on my other machines it isn’t , and it still works. Nor does the symlink, which I only tried through deperations since nothing else was working.

Is there a GRADLE DEVELOPER out there who can say exactly how gradle determines how to get to the JDK?


$ which java /usr/bin/java

$ echo $JAVA_HOME

/Library/Java/JavaVirtualMachines/jdk1.7.0_60.jdk/Contents/Home

$gradle -version ------------------------------------------------------------ Gradle 1.12 ------------------------------------------------------------

Build time:

2014-04-29 09:24:31 UTC Build number: none Revision:

a831fa866d46cbee94e61a09af15f9dd95987421

Groovy:

1.8.6 Ant:

Apache Ant™ version 1.9.3 compiled on December 23 2013 Ivy:

2.2.0 JVM:

1.7.0_60 (Oracle Corporation 24.60-b09) OS:

Mac OS X 10.9.3 x86_64

Why did you say your command line build was running with Java 6?

The output from “gradle -version” shows that Gradle is running with 7u60.

Just to confirm where it is picking it up from you could run the following build script

println "java.version = ${System.getProperty('java.version')}"
println "java.home = ${System.getProperty('java.home')}"

At least then you would know if it is somehow running from a JRE instead of a JDK.

Can you share a build script? Is this only happening for Android builds or does a basic Java project have issues as well?

Hi, I was just looking at the stack output where it mentions jdk6. Im not exactly sure why it does, maybe its legit?

(Ill get back to you with the script when I get home…thgx!)

org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45) at org.gradle.launcher.Main.main(Main.java:37) at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:50) at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:32) at org.gradle.launcher.GradleMain.main(GradleMain.java:23) Caused by: java.lang.RuntimeException: Cannot find System Java Compiler. Ensure that you have installed a JDK (not just a JRE) and configured your JAVA_HOME system variable to point to the according directory. at org.gradle.api.internal.tasks.compile.jdk6.Jdk6JavaCompiler.createCompileTask(Jdk6JavaCompiler.java:57) at org.gradle.api.internal.tasks.compile.jdk6.Jdk6JavaCompiler.execute(Jdk6JavaCompiler.java:44) at org.gradle.api.internal.tasks.compile.jdk6.Jdk6JavaCompiler.execute(Jdk6JavaCompiler.java:38) at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.delegateAndHandleErrors(NormalizingJavaCompiler.java:96)

All that ‘jdk6.Jdk6JavaCompiler’ means is that Gradle is using the Java compiler API introduced in JDK 6. In other words, it means that Gradle is compiling with JDK 6 or higher.

OK, the output of that script is:

java.version = 1.7.0_60 java.home = /Library/Java/JavaVirtualMachines/jdk1.7.0_60.jdk/Contents/Home/jre

I was initially concerned about the ‘jre’ on the end, but its the same output as from the machine that works fine, so I guess its OK?

The output is expected. ‘java.home’ always points to a JRE (namely the currently executing one). ‘jdk1.7.060.jdk/Contents/Home/jre’ is the internal JRE of the JDK.

top level build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

repositories {

mavenCentral()

}

dependencies {

classpath ‘com.android.tools.build:gradle:0.11.+’

// NOTE: Do not place your application dependencies here; they belong

// in the individual module build.gradle files

} }

allprojects {

repositories {

mavenCentral()

} }

app level build

apply plugin: ‘android’

android {

compileSdkVersion 19

buildToolsVersion “19.1.0”

defaultConfig {

applicationId “stef.myapplication”

minSdkVersion 16

targetSdkVersion 19

versionCode 1

versionName “1.0”

}

buildTypes {

release {

runProguard false

proguardFiles getDefaultProguardFile(‘proguard-android.txt’), ‘proguard-rules.pro’

}

} }

dependencies {

compile fileTree(dir: ‘libs’, include: [‘*.jar’]) }

So pretty much nobody knows how I have managed to fool gradle on this one osx machine?

are these expected values?

21:43:54.062 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter] Executing actions for task ‘:app:compileDebugJava’. 21:43:54.153 [DEBUG] [org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler] Compiler arguments: -source 1.6 -target 1.6 -d /Users/stef/AndroidStudioProjects/MyApplication/app/build/intermediates/classes/debug -g -encoding UTF-8 -bootclasspath /Applications/Android Studio.app/sdk/platforms/android-19/android.jar /Users/stef/AndroidStudioProjects/MyApplication/app/src/main/java/stef/myapplication/MyActivity.java /Users/stef/AndroidStudioProjects/MyApplication/app/build/generated/source/r/debug/stef/myapplication/R.java /Users/stef/AndroidStudioProjects/MyApplication/app/build/generated/source/buildConfig/debug/stef/myapplication/BuildConfig.java 21:43:54.154 [INFO] [org.gradle.api.internal.tasks.compile.jdk6.Jdk6JavaCompiler] Compiling with JDK Java compiler API. 21:43:54.171 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter] Finished executing task ‘:app:compileDebugJava’ 21:43:54.173 [LIFECYCLE] [class org.gradle.TaskExecutionLogger] :app:compileDebugJava FAILED 21:43:54.174 [INFO] [org.gradle.execution.taskgraph.AbstractTaskPlanExecutor] :app:compileDebugJava (Thread[main,5,main]) completed. Took 0.19 secs. 21:43:54.175 [DEBUG] [org.gradle.execution.taskgraph.AbstractTaskPlanExecutor] Task worker [Thread[main,5,main]] finished, busy: 0.928 secs, idle: 0.04 secs 21:43:54.181 [ERROR] [org.gradle.BuildExceptionReporter]

21:43:54.183 [ERROR] [org.gradle.BuildExceptionReporter] FAILURE: Build failed with an exception. 21:43:54.185 [ERROR] [org.gradle.BuildExceptionReporter]

21:43:54.186 [ERROR] [org.gradle.BuildExceptionReporter] * What went wrong: 21:43:54.186 [ERROR] [org.gradle.BuildExceptionReporter] Execution failed for task ‘:app:compileDebugJava’. 21:43:54.187 [ERROR] [org.gradle.BuildExceptionReporter] > Cannot find System Java Compiler. Ensure that you have installed a JDK (not just a JRE) and configured your JAVA_HOME system variable to point to the according directory. 21:43:54.193 [ERROR] [org.gradle.BuildExceptionReporter]

Hi Steve, I’m in exactly the same boat as you, I’ve been unable to build even a hello world Android Studio project on my macbook air, because of what looks like an identical gradle build problem:

Execution failed for task ‘:app:compileDebugJava’. > Cannot find System Java Compiler. Ensure that you have installed a JDK (not just a JRE) and configured your JAVA_HOME system variable to point to the according directory.

I’ve tried everything written about this problem including most of the things that you describe above. Perhaps if we compare notes we can get to the bottom of it.

I think the key to solving this problem is figuring out why the gradle ‘java.home’ system property points to the JRE directory rather than the JDK one.

If I execute this (suggested above) as a gradle build script:

buildscript { println “java.version = ${System.getProperty(‘java.version’)}” println “java.home = ${System.getProperty(‘java.home’)}” }

I get the following output with java.home pointing to the jre subdirectory, which doesn’t have bin/javac in it:

java.version = 1.7.0_60 java.home = /Library/Java/JavaVirtualMachines/jdk1.7.0_60.jdk/Contents/Home/jre

The JAVA_HOME in my environment points to the actual JDK home that has a bin/javac in it:

echo $JAVA_HOME /Library/Java/JavaVirtualMachines/jdk1.7.0_60.jdk/Contents/Home

Perhaps the key to solving this problem is getting gradle to use the JDK home rather than the JRE one?

I tried setting the java.home system property globally:

cat $HOME/.gradle/gradle.properties systemProp.java.home=’/Library/Java/JavaVirtualMachines/jdk1.7.0_60.jdk/Contents/Home’

This fixed the test build script:

java.version = 1.7.0_60 java.home = ‘/Library/Java/JavaVirtualMachines/jdk1.7.0_60.jdk/Contents/Home’

But unfortunately doesn’t help gradle find the compiler.

Perhaps the solution is a variation on this?

This is so odd. I see the same things in my JAVA_HOME and the Gradle values, yet I can compile Java.

$ echo $JAVA_HOME; gradle tasks /Library/Java/JavaVirtualMachines/jdk1.7.0_60.jdk/Contents/Home java.version = 1.7.0_60 java.home = /Library/Java/JavaVirtualMachines/jdk1.7.0_60.jdk/Contents/Home/jre :tasks …

This is working for me on two Macs with 10.9.3 and Gradle 2.0. (I hope saying this doesn’t jinx me.)