Skip to content
This repository has been archived by the owner on Feb 6, 2024. It is now read-only.

Applying plugin to Gradle KTS project fails #378

Closed
rock3r opened this issue Jun 22, 2020 · 6 comments
Closed

Applying plugin to Gradle KTS project fails #378

rock3r opened this issue Jun 22, 2020 · 6 comments

Comments

@rock3r
Copy link

rock3r commented Jun 22, 2020

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}")
            }
        }
    }
}
@rock3r
Copy link
Author

rock3r commented Jun 22, 2020

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

@loosebazooka
Copy link
Contributor

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

@loosebazooka
Copy link
Contributor

loosebazooka commented Jun 22, 2020

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.

@rock3r
Copy link
Author

rock3r commented Jun 22, 2020

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.

@loosebazooka
Copy link
Contributor

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

@rock3r
Copy link
Author

rock3r commented Jun 23, 2020

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"))
    }
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants