Gradle Kotlin Hello-World build.gradle.kts file marked red

According to kotlin-dsl-samples/samples at master · gradle/kotlin-dsl-samples · GitHub, one should be able to use vanilla Intellij 2017.1.4 and vanilla Kotlin plugin 1.1.2-5 to open a build.gradle.kts-based project. I tried to open the hello-world sample project in Intellij. While command-line ./gradlew clean build works and produces the .jar file properly, opening the build.gradle.kts file in Intellij will make it all red and autocompletion/navigation/documentation doesn’t work. Please, what further steps do I need to take, for the build.gradle.kts to work properly?

I have restarted IDEA couple of times, but it didn’t helped to resolve the issue.

This is a known issue in Gradle 4.1, it should have been already fixed in the latest builds of Gradle or Kotlin IDE plugin.

Thank you, the newest Kotlin IDE plugin 1.1.3 resolved the issue. Pure awesomeness.

Does IntelliJ have a standard way to change the Gradle wrapper version without having to use the terminal?

There is no standard way, but you can open the gradle.properties file from the gradle folder in the idea text editor and change it to desired version.

Probably the better way is to run ./gradlew --gradle-version 4.0 since that also updates the gradlew scripts and gradle-wrapper.jar.

I am seeing this issue now, I think I have all the latest stuff…
kotlin_version = “1.2.0”
distributionUrl=https://services.gradle.org/distributions/gradle-4.3-bin.zip
kotlin plugin 1.2.0-release-IJ2017.3-1
IntelliJ IDEA 2017.3 (Ultimate Edition)
Build #IU-173.3727.127, built on November 27, 2017

I used the New Module wizard to set it up and selected the kotlin dsl.

Significantly easier just to restart IntelliJ until the build.gradle.kts file is parsed properly.

Same for me. Did you solve it?

I’m finding this issue quite annoying. Seems even with Gradle 4.4 I have to randomly add/remove the plugin java part to make it parse. Once it parses it’s okay until the next time I load up IntelliJ IDEA.

I’m only a few days into all of Kotlin, Idea, and Gradle, so am having a bit of information overload. My build.gradle.kts file is not parsing and is marked red as well. Does this matter? What do I need to do to fix it if so? I have fresh installs of everything.

I’ve the same issue on Windows. I’m also on latest versions Gradle 4.4.1, IDEA 2017.3.2, kotlin 1.2.10
It’s fair to say that everything work fine right after I create a new project. After I close the project and re-open it the script file never compiles. Tips from other threads like removing gradle caches don’t work.

Any tips?

Works fine under macOS tough.

I found steps that work for me. See: Kotlin DSL syntax error for build.gradle.kts - #13 by jstuyts

1 Like

They worked for me too.