This can probably be obvious to Kotlin developers, but values of the mainClassName
property for Kotlin classes should include the Kt
postfix, if the corresponding application is a Kotlin class.
For example, a Kotlin ExampleApplication
like
package com.example
@SpringBootApplication
class ExampleApplication
fun main() {
runApplication<ExampleApplication>()
}
would require specifying its entry point as
springBoot {
mainClassName = "com.example.ExampleApplicationKt"
}
and not "com.example.ExampleApplication"
(as shown in the Reference).
Comment From: wilkinsona
Thanks for the suggestion. The Kotlin examples in the Gradle plugin's documentation are for configuring Gradle using its Kotlin DSL. It's not intended to imply that the application itself has been written in Kotlin. That said, there's no harm in including a tip in the section on configuring the application's main class.
Comment From: fernandezseb
Hey, I'd gladly make a PR to add a note. I would add something along the lines:
If the main class is written in Kotlin, the name of the generated Java class should be used, because the Kotlin function
fun main(args: Array<String>)
is defined at the package-level. By default this is the name of the Kotlin class with theKt
suffix added. For example:ExampleApplication
becomesExampleApplicationKt
. (If another name is defined using the@JvmName
annotation, then that name should be used.)
Comment From: wilkinsona
@fernandezseb Yes, please. That'd be great. FWIW, I'd omit "because the Kotlin function fun main(args: Array<String>)
is defined at the package-level" purely in the interests of brevity.
Comment From: wilkinsona
Closing in favour of #23418.