Download The Ultimate Tutorial: Getting Started With Kotlin

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!

Archive Monthly Archives: June 2018

How to fix Gradle 4.4/4.7 + JDK 10 issue on IntelliJ IDEA 2018.1.x


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.

Step-by-step Guide

  1. If you already have a project created, great! Otherwise, create the project in IntelliJ using Gradle project template (be it Kotlin, Java, or something else).

    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 /.../.../
    Could not determine Java version using executable /.../.../

    That is fine, move on to the next step.

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

  3. In the terminal, switch to your project directory

    cd ~/path/to/your/project/

  4. Generate Gradle Wrapper script with the version set to 4.7

    gradle wrapper --gradle-version 4.7

    This command is going to download Gradle 4.7, create scripts gradlew and 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.

  5. Open IDEA preferences and type gradle in the search field:

    Search for “gradle” and select “Build, Execution, Deployment / Build Tools / Gradle”
    Search for “gradle” and select “Build, Execution, Deployment / Build Tools / Gradle”

  6. Select Build, Execution, Deployment -> Build Tools -> Gradle in the sidebar like in the picture above.

  7. In this section of the settings select Use gradle ‘wrapper’ task configuration:

    Select “Use gradle ‘wrapper’ task configuration”
    Select “Use gradle ‘wrapper’ task configuration”

  8. Press the OK button.

  9. 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
    Gradle 4.7 version is being downloaded during Gradle Sync

Downsides of this temporary fix

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

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.