Buildship can not find dependency; Gradle can

I have buildship 1.0.12 installed in eclipse. When I run the build.gradle from a windows command prompt, it completes successfully. When I try to run it by highlighting my build.gradle and using “run configurations” it fails because it says it cannot find tools.jar. Prior to running the jar task I print the dependencies and it shows the tools.jar file.

Gradle User Home: C:\Users\Mike.gradle
Gradle Distribution: Gradle wrapper from target build
Gradle Version: 2.12
Java Home: C:\Java
JVM Arguments: None
Program Arguments: None
Gradle Tasks: clean eclipse printDependencies jar

:clean
:eclipseClasspath
:eclipseJdt
:eclipseProject
:eclipse
:printDependencies
C:\Java\jdk1.8.0_77\lib\tools.jar
C:\Users\Mike.gradle\caches\modules-2\files-2.1\com.microsoft.sqlserver\sqljdbc4\4.2.6420.100\4d8a1bc64ddf2099dbc2a171e113f6654a1c02a6\sqljdbc4-4.2.6420.100.jar
C:\Users\Mike.gradle\caches\modules-2\files-2.1\org.slf4j\slf4j-api\1.7.10\5b338f206827d88acd890739f400a9b7664e5984\slf4j-api-1.7.10.jar
C:\Users\Mike.gradle\caches\modules-2\files-2.1\ch.qos.logback\logback-classic\1.1.2\b316e9737eea25e9ddd6d88eaeee76878045c6b2\logback-classic-1.1.2.jar
. . . .
:compileJava FAILED

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ‘:compileJava’.

Could not find tools.jar

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

BUILD FAILED

tools.jar IS located in C:\Java\jdk1.8.0_77\lib

Any ideas on what could be my issue?

Hi Mike,

the tools.jar does not belong on your dependency list. It is not one of your dependencies, it is the compiler.

You are probably running Eclipse with a JRE instead of a JDK. Buildship starts Gradle with the same runtime that Eclipse uses by default. There are several solutions you can go for, but the simplest is this one:

In your ~/.gradle/gradle.properties, set the org.gradle.java.home property. This will ensure that Gradle uses this Java installation no matter from where it is started. See the user guide for more information

Cheers,
Stefan