appengine-plugins icon indicating copy to clipboard operation
appengine-plugins copied to clipboard

Improve Gradle Kotlin DSL compatibility

Open Petikoch opened this issue 5 years ago • 4 comments

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

Petikoch avatar May 22 '19 07:05 Petikoch

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?

loosebazooka avatar Jun 19 '19 21:06 loosebazooka

I don't know @loosebazooka ... I'm not an expert on that. Maybe one of the Gradle Guru's like @eskatos can help?

Petikoch avatar Jun 24 '19 08:06 Petikoch

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 of configure<AppEngineAppYamlExtension> { ... }
  • Allow cloudSdkHome instead of setCloudSdkHome( ... )
  • Documentation/Examples for Kotlin

kulmanf avatar Apr 26 '20 09:04 kulmanf

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)

rock3r avatar Jun 22 '20 15:06 rock3r