Bits and pieces were available online but it took some time to piece it all together. I’m sharing it her in hopes it can save others from having to figure it out again. For those that just want to grab the Kotlin DSL version is here:
Figuring this all out
There are some general Groovy vs Kotlin syntax changes we will need to handle here and in the rest of the code:
single quotes need to become double quotes
methods like classpath, implementation, testImplementation need parenthesis around them.
In the Groovy DSL you can use deprecated “compile” syntax for adding dependencies as well as the newer “implementation” syntax. We can only use the later in the Kotlin DSL.
I also updated the plugin version as the comment in the original example suggests.
Deploy and stageStandard tasks depend on the test task
This answer on Stack Overflow explains the syntax I used for getting the plugin’s deploy task and stageStandard task to depend on the test task.
One tricky part is figuring out the correct type to supply to withType. The good news is if you get the type wrong gradle will complain with something like:
The task ‘appengineDeploy’ (com.google.cloud.tools.gradle.appengine.core.DeployTask) is not a subclass of the given type (org.gradle.api.tasks.compile.JavaCompile).
So you can figure it out through trial and error…
This issue on Github explains the necessary syntax for the final deploy block.
The tests block
First change we need to do is wrap the block in a tasks block.
This conversion is also tricky because the Groovy DSL expects Groovy closures and we need to convert them to Kotlin closures. There is a small example on Github which covers how to use this “closureOf” method to handle the conversion. Note that when dealing with a closure that takes two arguments we need to use “KotlinClosure2” instead which I figured out from this blog.
An additional tricky part with this is we need to explicitly provide the type of the arguement(s) to closureOf and KotlinClosure2. In my case I was able to figure out the type by looking at the documentation for the test tasks which includes the full method signatures with types. This let me understand that “beforeTest” needs a TestDescriptor, “onOutput” needs TestDescriptor and TestOutputEvent, and “afterTest” needs TestDescriptor,TestResult.