Google Cloud Functions Kotlin kts Sample

I tried to use Kotlin with GCF but struggled with build.gradle.kts.

In the code I often see on the net, the runFunction of the task did not work.

Here is the version of build.gradle.kts that worked.

The difference between the most commonly seen samples is

main= ""


mainClass= ""

Causes and Countermeasures

The cause is that in JavaExec with gradle7, the main class property is ‘main’.
However, this was deprecated in 8.0 and the ‘mainClass’ property is used.
The information on many websites is written in gradle as main = ”.

I was able to rewrite build.gradle to build.gradle.kts while asking questions to the AI assistant and copilot.

Google Cloud Functions Kotlin kts Sample