GoogleCloudPlatform / app-gradle-plugin

The library has moved to https://github.com/GoogleCloudPlatform/appengine-plugins/tree/main/app-gradle-plugin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Applying plugin to Gradle KTS project fails

rock3r opened this issue · comments

I am creating a project using Gradle 6.5 and the Kotlin DSL. When I add the appengine plugin to my :api-server module I get this error:

An exception occurred applying plugin request [id: 'com.google.cloud.tools.appengine', version: '2.2.0', artifact: 'com.google.cloud.tools:appengine-gradle-plugin:2.2.0']
> Failed to apply plugin [class 'com.google.cloud.tools.gradle.appengine.standard.AppEngineStandardPlugin']
   > Task with name 'assemble' not found in project ':api-server'.

It looks like the plugin is trying to access the assemble task before it's created. My plugins block looks like this:

plugins {
    kotlin("jvm")
    kotlin("plugin.serialization") version "1.3.72"
    id("com.google.cloud.tools.appengine") version "2.2.0"
    application
    war
}

Changing the plugins order doesn't change the result.

PS: I am using a resolutionStrategy in my settings.gradle.kts to be able to reference the plugin — not that it has anything to do with the issue at hand:

pluginManagement {
    resolutionStrategy {
        eachPlugin {
            if (requested.id.id == "com.google.cloud.tools.appengine") {
                useModule("com.google.cloud.tools:appengine-gradle-plugin:${requested.version}")
            }
        }
    }
}

Adding to this, if I use the "old school" plugin syntax:

buildscript {
    repositories {
        jcenter()      
        mavenCentral()
    }
    dependencies {
        classpath("com.google.cloud.tools:appengine-gradle-plugin:2.2.0")
    }
}
apply(plugin = "com.google.cloud.tools.appengine")

Then Gradle complains that it doesn't know what to do with the appengine block:

e: [...]/api-server/build.gradle.kts:21:1: Unresolved reference: appengine
e: [...]/api-server/build.gradle.kts:22:5: Unresolved reference: deploy
e: [...]/api-server/build.gradle.kts:23:9: Unresolved reference: projectId

Edit: this is solved by using configure<AppEngineStandardExtension> or configure<AppEngineAppYamlExtension> instead of appengine

commented

does apply the plugin of choice directly work?

apply(plugin = "com.google.cloud.tools.appengine-appyaml")

as described here: https://github.com/GoogleCloudPlatform/app-gradle-plugin/blob/master/USER_GUIDE.md#applying-the-plugin

commented

So there are some known issues with the new syntax, given plugin resolution order (we need to delay applying the task dependencies I think). However it has been low priority for us and I haven't really worked on it a while. Perhaps the team can put some cycles on it, or we could use external contributor help.

This plugin could probably use some other updates as it is currently built against gradle 4.9.

I finally got it to work in the "old way" as you said, collecting bits and pieces from various answers on issues, but maybe it looks like you should be using the configuration avoidance friendly, TaskProvider-based APIs to retrieve the assemble task. May solve the issue. I think the issue is purely of timing, due to the plugins block being run before everything else.

commented

Agree, there's some work to be done here to bring things up to date.

For anyone else having issues with the plugin with the Kotlin DSL, and stumbling on this issue, here's the current workaround:

plugins {
    kotlin("jvm")
    application
    war
}

buildscript {
    repositories {
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath("com.google.cloud.tools:appengine-gradle-plugin:2.2.0")
    }
}

// Note: the AppEngine plugin currently does not work when applied using the
// plugins DSL, so we need to use the old-school way
apply(plugin = "com.google.cloud.tools.appengine")

configure<AppEngineStandardExtension> {
    deploy {
        projectId = "[TODO]"
        version = "[TODO]"
    }
}

tasks {
    val run by registering {
        dependsOn(named("appengineRun"))
    }
}