Repository: google/protobuf-gradle-plugin

Issue #444: Gradle Kotlin DSL changed method signature of NamedDomainObjectContainerExtensionsKt.invoke
Created: 2020-11-03T16:21:55Z
In KtDslCompatibilityUtils.java the plugin calls NamedDomainObjectContainerExtensionsKt.invoke(container, block) with block being a Function1<? super NamedDomainObjectContainerScope<T>, Unit>. In the latest Gradle build (6.8-milestone-2), that signature has been changed to Action<NamedDomainObjectContainerScope<T>>: gradle/gradle@593001e, so builds using the Kotlin DSL fail using new builds.

Duplicate issue #495: Stop using deprecated NamedDomainObjectContainer.invoke(kotlin.Function1)
Created: 2021-05-08T15:54:11Z
Using the protobuf plugin with a recent gradle version prints
Using method NamedDomainObjectContainer<T>.invoke(kotlin.Function1) has been deprecated. This is scheduled to be removed in Gradle 8.0. Recompile your plugin against Gradle >= 6.8 Consult the upgrading guide for further information: https://docs.gradle.org/7.0/userguide/upgrading_version_6.html#using_NamedDomainObjectContainer_invoke_kotlin_Function1
        at org.gradle.kotlin.dsl.NamedDomainObjectContainerExtensionsKt.invoke(NamedDomainObjectContainerExtensions.kt:61)
        at com.google.protobuf.gradle.KtDslCompatibilityUtils.configureNamedDomainObjectContainer(KtDslCompatibilityUtils.java:32)
        at com.google.protobuf.gradle.ProtobufConfiguratorExtsKt$plugins$1.invoke(ProtobufConfiguratorExts.kt:123)
        at com.google.protobuf.gradle.ProtobufConfiguratorExtsKt$plugins$1.invoke(ProtobufConfiguratorExts.kt)
        at org.gradle.kotlin.dsl.KotlinClosure1.doCall(GroovyInteroperability.kt:94)
        at java.base/java.lang.reflect.Method.invoke(Method.java:567)
        at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:323)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1268)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1035)
        at groovy.lang.Closure.call(Closure.java:412)
        // ...

The problem is this wrapper, which still uses the old function with a kotlin function interface instead of the Gradle Action class. I tried to fix this myself but it looks like org.gradle:gradle-kotlin-dsl is no longer getting published and the version this project depends on doesn't have the new api yet. I think that wrapper should create an action and use the newer method if its running in Gradle >=6.8 to avoid the deprecation warning.

Closing comment (2021-05-10T19:31:07Z): Duplicate of #444.
Gradle has reverted the API deletion at gradle/gradle#15508. Try upgrading Gradle to 6.8 RC3 or later if you are experiencing this issue.

I tried to fix this myself but it looks like org.gradle:gradle-kotlin-dsl is no longer getting published and the version this project depends on doesn't have the new api yet.

Right, I cannot find newer releases of gradle-kotlin-dsl and had filed gradle/gradle#16884 to Gradle.

I think that wrapper should create an action and use the newer method if its running in Gradle >=6.8 to avoid the deprecation warning.

The issue is still we need the compile-time dependency of gradle-kotlin-dsl containing both the Function and Action variants of the API (unless using reflection, which isn't a good solution).
For now, there isn't a nice solve-for-all solution, until Gradle releases a backward-compatible artifact. We'd ask users to avoid using the broken versions (Gradle v6.8.0-M2 to v6.8.0-RC2).