appengine-plugins
appengine-plugins copied to clipboard
Improve Gradle Kotlin DSL compatibility
Hi!
I'm switching over in my Gradle build files from Groovy (build.groovy) to the Gradle Kotlin DSL (build.groovy.kts).
(using Gradle 5.4.1)
It is not obvious IMHO, that the Groovy version of the appengine configuration section (build.gradle)
appengine {
tools {
// configure the Cloud Sdk tooling
}
stage {
// configure staging for deployment
}
deploy {
// configure deployment
}
}
must be written (AFAIK) like this, using the Gradle Kotlin DSL (build.gradle.kts)
import com.google.cloud.tools.gradle.appengine.appyaml.AppEngineAppYamlExtension
// ...
the<AppEngineAppYamlExtension>().apply {
tools {
// configure the Cloud Sdk tooling
}
stage {
// configure staging for deployment
}
deploy {
// configure deployment
}
}
Could you add some Gradle Kotlin DSL examples somewhere in the https://github.com/GoogleCloudPlatform/app-gradle-plugin/blob/master/USER_GUIDE.md ?
Thanks a lot and best regards, Peti
This is strange, I would ideally like the kts version to be more straight forward. Are we doing something weird in our config that makes it hard to do this?
I don't know @loosebazooka ... I'm not an expert on that. Maybe one of the Gradle Guru's like @eskatos can help?
import com.google.cloud.tools.gradle.appengine.appyaml.AppEngineAppYamlExtension
apply(plugin = "com.google.cloud.tools.appengine")
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("com.google.cloud.tools:appengine-gradle-plugin:2.2.0")
}
}
// AppEngine Configuration
configure<AppEngineAppYamlExtension> {
tools {
// configure the Cloud Sdk tooling
setCloudSdkHome(File("C:/Program Files (x86)/Google/Cloud SDK/google-cloud-sdk"))
cloudSdkVersion = "290.0.0"
}
stage {
// configure staging for deployment
}
deploy {
// configure deployment
projectId = "noneofyourbusiness"
version = "gradle-deployed-prod"
}
}
Here is my working configuration. It has been a very frustrating experience.
Things that could be done to improve the compatibility with the Kotlin DSL
-
configure<AppEngine> { ... }
instead ofconfigure<AppEngineAppYamlExtension> { ... }
- Allow
cloudSdkHome
instead ofsetCloudSdkHome( ... )
- Documentation/Examples for Kotlin
You can have a nicer API by providing an extension function like the one the application
plugin has:
fun org.gradle.api.Project.`application`(configure: org.gradle.api.plugins.JavaApplication.() -> Unit): Unit =
(this as org.gradle.api.plugins.ExtensionAware).extensions.configure("application", configure)