My file name is build.gradle.kts
My settings file is settings.gradle.kts
I have added plugins { application }
and yet when I try application { mainClass.set(...) } I get an “Unresolved reference: mainClass” error
As you might guess, using the Groovy syntax (mainClassName = "MainKt") works.
I just don’t understand how the instructions can be so simple yet resolving a problem is so difficult. The word “unresolved” doesn’t even appear on the page to help troubleshoot, nor is it possible to search within the docs.
An “Unresolved reference” is a generic programming term and is coming from the Kotlin compiler, not Gradle. It just means that you’re referencing something that isn’t defined.
This is going to be less about the “Groovy syntax” and more about what the types of the properties and when they were introduced. The mainClassName property is a String. In Gradle 6.4, the mainClass property was introduced, which is a Property<String>. While you’re referencing the Gradle 6.6 docs, based on what works, it looks like you’re actually executing the build with Gradle 6.3 (or earlier). The mainClass is unresolved because it hadn’t been added yet.