40

When I run Gradle project via Eclipse I get below error.

system 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.

Could not execute build using Gradle installation 'C:\gradle-1.2-all\gradle-1.2'.

But I have installed JDK 1.7 and set the JAVA_HOME environment variable.

Community
  • 1
  • 1
surekha
  • 401
  • 1
  • 4
  • 4

12 Answers12

62

Go to File -> Other Settings -> Default Project Structure

enter image description here

Now Set your JDK location

enter image description here

Kishan Vaghela
  • 7,678
  • 5
  • 42
  • 67
52

In Preference of Eclipse (main menu: Window -> Preferences), select

Gradle -> Arguments -> Java Home, select "Workspace JRE".

Then select one of your jdk in your workspace.

On my laptop it's "jdk1.6.0_45". Yours should be the JDK 1.7 home folder, something like "/usr/lib/jvm/java-7-openjdk-amd64/".

Leo
  • 1,710
  • 2
  • 26
  • 29
  • Thanks, I was having the exact same problem after creating a new workspace and getting started with Gradle. I just had to setup my JDK in eclipse, and follow your instructions above. – medloh Aug 13 '14 at 16:57
  • 4
    Hi, Am not sure why I am not getting Arguments option in Gradle - eclipse - window - preferences. – Delli Kilari May 06 '17 at 05:07
15

You can face this problem even when all your system variables are set and correct. Usually this happens when you work with foreign code from Github etc.

So what you have to do is to check gradle version in your project level build.gradle file, and if it doesn't match to current installed version, update it.

buildscript {
    //other setupps
    dependencies {
        classpath 'com.android.tools.build:gradle:1.0.0' //update this to your current version
    }
}
Dmitry Smolyaninov
  • 2,159
  • 1
  • 18
  • 32
  • 3
    Thanks so much. I tried everything related to environmental variables and jdk versions, and this was the issue all along. Wrong gradle version. Worst error message ever. – eirik Apr 10 '17 at 12:08
13

In Gradle Task View -> build -> right click->Open Gradle Configuration -> JAVA_HOME -> and put the current value of your enviroment, something like C:\Program Files\Java\jdk1.7.0_79

I hope this help you

Fernando Bustos
  • 349
  • 3
  • 6
4

I tried following, but in Eclipse (luna), Run as, "gradle build Gradle build", still failed.

  1. change JAVA_HOME

  2. Preference, Gradle -> Arguments -> Java Home, select "Workspace JRE".

Solution: Go command line, run gradle build as answered by user3754672, then back to Eclipse, all working.

Community
  • 1
  • 1
oopsmails
  • 171
  • 1
  • 7
3

It's likely you haven't installed a JDK. Even though you have "jdk1.7", you may have only the runtime environment. You may need to install the "-devel" option for the package, for example, both these would be required:

  • java-1.7.0-openjdk
  • java-1.7.0-openjdk-devel

If you can't find the right package, tell us your distro and the exact name of the jdk1.7 package you have so we can help more.

Quinn Comendant
  • 9,686
  • 2
  • 32
  • 35
3

Although you may have a full JDK installed somewhere, and pointed to by JAVA_HOME, I don't think the Eclipse Gradle plugin will use it by default. I ran into the same problem running the the "test" target for the Gradle "quickstart" app in Springsource Groovy/Grails Tool Suite 3.3.0(Gradle IDE 3.3.0.201307040643 plugin).

If you re-run the failed Gradle target from the "External Tools" menu (under the "arrow with a suitcase icon"), adding "--debug" in the "Program Args" under the Arguments tab, it will show you in the console what JVM/JDK it uses. I was able to get around the problem by deselecting "Use Gradle wrapper's default" in the Java Home section of the Arguments tab, and replacing it with an Execution Environment setting that pointed to my 1.7 JDK that I had installed. I'm sure there's a way to have it do this by default, so you don't have to configure each targets run configuration, but this method should fix the immediate problem.

roninjoe
  • 361
  • 2
  • 7
3

I think the wrapped gradle uses the same java as eclipse. Since Eclipse seems to use jre by default you can get the issue mentioned in the question. Try this: Go to your eclipse.ini and add -vm argument like this:

-vm
c:/java/jdk1.8/javaw.exe
apreg
  • 637
  • 8
  • 18
2

Issue

Using the Eclipse -> gradle -> select task to execute and error "...cannot find system java compiler."

Solution

Go to the path where your build.gradle path is... and using the cmd manually type gradle build <- this will work.

Done.

Back to Eclipse and execute the gradle task. It will work again!

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
ChokYeeFan
  • 293
  • 1
  • 3
  • 8
  • doesn't this defeat some of the purpose of using the ide to being with? It worked for me also, but isn't the desired total solution. – dethSwatch Feb 18 '16 at 16:06
  • This post gave me the indication that my Eclipse is mis-configured. – kiltek Feb 22 '16 at 14:18
2

Change your gradle to min: classpath 'com.android.tools.build:gradle:2.0.0'and then Android Studio will ask you to update it. You will make and update of gradle and after that it will work.That is how I fixed it for me.

Georgi Georgiev
  • 362
  • 6
  • 9
0

I deleted some old jdk's and encountered the same issue. None of the above outdated solutions worked. Gradle in its infinite wisdom stores the JDK location in C:\Users\User.gradle\gradle.properties. This property is not accessible via the IDE as far as I know.

Rory G
  • 173
  • 1
  • 11
0

My Eclipse version: Eclipse Java EE IDE for Web Developers. Version: Photon Release (4.8.0)

Right click 'gradle.build' and then choose 'run as' -> 'Run Configurations'. In the left, choose 'gradle.build' under 'Gradle Project'. In the right, you could see something like 'Gradle Tasks', 'Project Settings', 'Java Home' and so on. Choose 'Java Home', you will see there is an input box. Put your JDK path there. (something like: C:\Program Files\Java\jdk-10) And then run.

iluhz
  • 1
  • 2