350 pages of hands-on tutorial right into your email inbox. Learn how to use state of the art development environment and build a full-fledged command-line application. You will receive free updates to the tutorial. Start learning Kotlin today!
Hi there, a few days ago I tried to build a Kotlin project using the latest OpenJDK 10, and it turned out that there is a problem with IntelliJ IDEA 2018.1.4 running an older version of Gradle. This article contains a step-by-step guide on how to fix this.
More about the issue here. The fix is already in the master branch and releases in one of the next versions of IntelliJ, but if you need the solution right now, read on.
This fix is temporary, and you should update to the newest version of IntelliJ as soon as it is released.
After you are done creating the project, you’ll see an error message that Gradle 4.4 can’t detect the version of your JDK:
Could not determine Java version using executable /.../.../
That is fine, move on to the next step.
Install any recent version of Gradle on your system using the official instructions
You may skip this step if you already have Gradle installed and it is available as a terminal/command-line binary
gradle on your PATH.
In the terminal, switch to your project directory
Generate Gradle Wrapper script with the version set to
gradle wrapper --gradle-version 4.7
This command is going to download Gradle 4.7, create scripts
gradlew.bat for your current project. From this point, you should use these scripts in the command-line.
Next step, is to make sure that IntelliJ IDEA uses those, instead of built-in Gradle distribution.
Open IDEA preferences and type
gradle in the search field:
Search for “gradle” and select “Build, Execution, Deployment / Build Tools / Gradle”
Build, Execution, Deployment -> Build Tools -> Gradle in the sidebar like in the picture above.
In this section of the settings select
Use gradle ‘wrapper’ task configuration:
Select “Use gradle ‘wrapper’ task configuration”
Press the OK button.
The project should be re-built (re-synced) automatically and you should see that it is downloading the Gradle 4.7:
Gradle 4.7 version is being downloaded during Gradle Sync
This fix introduces another (bearable) problem:
Every time you change your Gradle configuration IntelliJ IDEA downloads Gradle 4.7 again.
Gladly, it doesn’t do that when running tests and building your software.
Thank you for reading. Make sure to share this guide with anyone who wants to use Gradle 4.7 with IntelliJ IDEA 2018.1.x.