Search code examples
kotlingradlegradle-plugingradle-kotlin-dsl

Gradle 8 plugin-publish fails with "class org.gradle.api.internal.provider.DefaultSetProperty cannot be cast to class java.util.Collection" error


When I upgraded my Gradle version from 7.x to 8.x, and then tried to publish my plugin, I encountered the following vague error:

Cause: class org.gradle.api.internal.provider.DefaultSetProperty cannot be cast to class java.util.Collection ( org.gradle.api.internal.provider.DefaultSetProperty is in unnamed module of loader org.gradle.internal.classloader.VisitableURLClassLoader @66cd51c3; java.util.Collection is in module java.base of loader 'bootstrap' )

The only relevant changes I made was removing the pluginBundle block:

pluginBundle {  
    website = "..."  
    vcsUrl = "..."  
    tags = listOf("...")  
}

And migrated them to the latest practice as these were moved to the gradlePlugin by the Gradle team to improve/simplify the process:

gradlePlugin {  
    website.set("...")  
    vcsUrl.set("...")  
  
    plugins {  
        create("...") {  
            id = project.group.toString()  
            displayName = project.name  
            description = project.description.toString()  
            implementationClass = "..."  
            tags.set(setOf("..."))  
        }  
    }}

These were nipped off straight from the official documentation, so I am surprised this is failing. If it helps, here are my relevant project dependency details:

Dependency Version
Kotlin 1.8.10
Java 17
Gradle 8.0.2
com.gradle.plugin-publish 1.0.0
io.github.gradle-nexus.publish-plugin 1.1.0

Solution

  • Upgrade com.gradle.plugin-publish to 1.1.x. The version 1.0.0 had a critical bug that makes it fail when solely relying on the gradlePlugin block:

    Version 1.1.0 (latest)

    • Fix a bug in handling tags, when solely relying on gradlePlugin block for configuring plugin publication
    • Forbid bypassing the Maven Publish plugin for generating plugin publication metadata

    See: com.gradle.plugin-publish/1.1.0

    The pluginBundle block was marked for removal in 8.0. So when you upgraded from 7.x you had to move these attributes to the gradlePlugin, that's why you encountered this error. You can also see this note in the docs/publish-plugin advising to upgrade:

    NOTE: If you are using version 1.0.X of the plugin, please update to at least version 1.1.0, which contains critical bug fixes.

    So, simply upgrading to 1.1.x should resolve the problem...

    Other helpful resources: