How to reproduce :
https://github.com/xmlking/reactive-apps

This is happening for me as well, I'd be very interested in how to fix it.
After upgrading to latest EAP IntelliJ and gradle 4, don't see this issue
Same for me on Gradle 4.0 and 2017.2 EAP 172.2953.9. However, if I open the project with 2017.1.4, and then go back to the EAP it works fine.
Digging further it looks like the EAP isn't automatically setting up / linking the gradle project, but 2017.1.4 does.
I see this behaviour on 2017.2.2 EAP. My gradle is 4.0, though my project is using 4.1 with a wrapper.
I see this behaviour on 2017.2.5, so any solution
I just tried opening the reproducer project (https://github.com/xmlking/reactive-apps) in IntelliJ 2017.2.5 with the Kotlin Plugin 1.1.51. I did not run the build from the command line before that, so importing took time downloading all the dependencies.
Once IntelliJ had finished importing the project I opened the root build.gradle.kts file. It was all red at first display, then IntelliJ started resolving the script dependencies, once done (<1s), everything looked normal:

@xmlking, @akofke, @CarsonF, @crummy, @hanct, @ps-aux, @wemu, can any of you reproduce the issue and share build/steps?
They are working fine now. Also tested with latest gradle 4.2.1 in project @ https://github.com/xmlking/microservices-observability and no issues with IntelliJ
We can close the ticket.
eskatos: it works. Tested it with latest gradle
Thank you @xmlking & @hanct!
Closing
I dont understand. My own project folder contains build.gradle.kts, and its content is only few lines as shown below, and yet there are red lines all over the place
plugins {
java <--expression expected, but a package name found
}
application { <--unresolved reference: application
mainClassName = "ro.jtonic.tests.gradlekt.MyClass" <--unresolved reference: mainClassName
}
gradle distribution 2.5.1
That is way too old.
You need at least Gradle 3.5 I think to have any grade script kotlin support.
You should try and use Gradle 4.2 to get these features.
Sorry, typo error. Should be Gradle 4.2.1.
I am using the latest gradle version.
Try Invalidating caches and restarting IntelliJ.
If that doesn't work go to Help > Show Logs In Finder and see if there are any useful errors in your IntelliJ logs.
Sometimes I have to close and re-open the IntelliJ project for everything to work. Especially after gradle updates.
Hi,
I try invalidate cache, restart Intellij, recreate new project, etc.... (try for few days already), I still get red line in the build.gradle.kts.
Below I show a screenshot, to show the error and configuration. As we can see, there are only 3 lines in the kts file now, so quite straightforward, but I still get the "expression expected, but a package name found" for the java keyword. Not sure why.
*Notice that my external libraries only contain Java 1,8 jdk. Thats' all.

I sometimes have similar effects when opening gradle builds in Intellij. But for both .gradle and .kts build files. So I assume its more on the Intellij side. Sometimes these red markers go away and Intellij does recognize its not only groovy or kotlin but a gradle file. Haven't found out yet what prevents this. It only ever worked with later gradle 4.2 RCs.
Sometimes executing a few tasks on the command line via the wrapper makes it go away. Invalidating the caches wont do this every time. When starting from scratch... well - maybe adding the java plugin and then just ./gradlew build once?
ok. Thanks. I think i manage to resolve the red color error in my build.gradle.kts. Finally!
What i mainly do is invalidate cache and delete away the .gradle folder in my user folder and boom! the error gone. I think the latter action (delete away the .gradle folder) could be the one resolving the issue
Thanks everyone for your great help!!!
Using
IntelliJ IDEA 2017.3.1 (Ultimate Edition)
Build #IU-173.3942.27, built on December 11, 2017
I hit the same issue
re-start of the IDE and then build->Rebuild Project fixed the issue
With a new created project using intellij idea's new module wizard.
I tried remove .gradle under home dir, .gradle under project dir, invalidate cache and restart, rebuild project ... and still got lots of errors,
build info:
IntelliJ IDEA 2018.1 (Ultimate Edition)
Build #IU-181.4203.550, built on March 27, 2018
Licensed to dollyn sun
Subscription is active until March 21, 2019
JRE: 1.8.0_152-release-1136-b20 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.13.3
idea.log
idea.log
Most helpful comment
ok. Thanks. I think i manage to resolve the red color error in my build.gradle.kts. Finally!
What i mainly do is invalidate cache and delete away the .gradle folder in my user folder and boom! the error gone. I think the latter action (delete away the .gradle folder) could be the one resolving the issue
Thanks everyone for your great help!!!