I'm writing some tests for a Kotlin Gradle plugin ...
# intellij
a
I'm writing some tests for a Kotlin Gradle plugin using Gradle TestKit. I'm writing
build.gradle.kts
files using multiline strings, and I'd like to use IntelliJ Language Injection so it looks pretty. I've set
@Language("kotlin")
, however, IntelliJ doesn't like it and shows an error. Is there a way of telling the language injection to highlight a string as if it were a
.gradle.kts
file?
Copy code
fun File.`build gradle kts`(@Language("kotlin") contents: String): File =
    createFile("build.gradle.kts", contents)
c
kotlin != Gradle Kotlin DSL; without knowledge of the Gradle specifics (APIs / DSL), IntelliJ will only be able to get partway there. From the screenshot it looks like it’s complaining about now knowing what
plugins
is - rightfully so, cuz that is provided by Gradle. Perhaps there is a Language that is specific to Gradle Kotlin DSL build scripts? (not familiar with this aspect of IntelliJ)
a
There's no Gradle, kts, Kotlin Script in the list of options that are shown in the GUI
c
looks like you’re stuck with Kotlin, or could consider creating a custom language injection.
a
I don't think custom language injection exists I'm going to try defining the Gradle project in a test/resources directory. Then I can use IntelliJ to edit the files, which should be a bit nicer than a string
👍 1
Using
@Language("kts")
gets the result I want 👍
🌟 1