An hour of wasted effort to troubleshoot an error while trying to import a simple Java application using Gradle! Eventually I was able to fix the issue. But the work is not done yet, until I write a quick blog post and document the error and the resolution.
I have been setting up my development environment to get started creating a Spring Boot Microservice using Spring Initializr.
Spring Initializr provides an extensible API to generate quick-start projects with the dependencies you need. Check it out here — https://start.spring.io
SpringBoot is popularly used to develop Spring applications and it eliminates need of lot of the boilerplate configuration. It comes with an embedded Tomcat server and you can just browse to localhost:8080 once you run your application to view the result.
I bumped into the below error while trying to import an existing Gradle project —
Error Description —
Synchronize Gradle projects with workspace failed due to an error connecting to the Gradle build. Could not create an instance of Tooling API implementation using the specified Gradle distribution ‘https://services.gradle.org/distributions/gradle-2.13-bin.zip’.
Could not determine java version from ‘9.0.1’.
Caused by: org.gradle.internal.service.ServiceCreationException: Could not create service of type FileWatcherFactory using GlobalScopeServices.createFileWatcherFactory().
Caused by: java.lang.IllegalArgumentException: Could not determine java version from ‘9.0.1’. Seems like this is an issue with the Gradle version being incompatible with Java version 9.Upgrading the gradle version can actually fix this issue.
After reading the error details, it looked to me as if the Gradle version was not compatible with the Java Version.
I modified the distributionUrl field in the gradle-wrapper.properties file to point to the latest gradle version 4.4.1. This properties file is present in the project/gradle/wrapper folder.
Incase you are using the Gradle Project Import Wizard, you can also specify the version of Gradle you want to use —
Once I did that I was able to successfully synchronize the Gradle Build with my workspace and run my Java application.
Hopefully this blogpost is helpful and if you bump into a similar error while importing or running your Java application make sure you have compatible versions of Gradle and JDK installed.