Vampire
03/14/2024, 2:36 PMkotlin-dsl
plugin and contains a pre-compiled script plugin (also had this with plain-old .kt
file under same circumstances).
If I have simplified this code in the plugin:
val artifactsGetter: Provider<Configuration>.(Action<AttributeContainer>) -> Provider<ArtifactView> =
{ attributesAction -> map { it.incoming.artifactView { attributes(attributesAction) } } }
configurations
.runtimeClasspath
.artifactsGetter {
attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, ArtifactTypeDefinition.JAR_TYPE)
}
It compiles perfectly fine.
But if I try to apply that plugin, I get
class Bar_gradle$$$result$1 cannot be cast to class org.gradle.api.Action (Bar_gradle$$$result$1 is in unnamed module of loader org.gradle.internal.classloader.VisitableURLClassLoader$InstrumentingVisitableURLClassLoader @649f4a9; org.gradle.api.Action is in unnamed module of loader org.gradle.internal.classloader.VisitableURLClassLoader @5f9d02cb)
If I look at the bytecode with javap
what is generated is
final class Bar_gradle$$$result$1 extends kotlin.jvm.internal.Lambda implements kotlin.jvm.functions.Function1<org.gradle.api.attributes.AttributeContainer, kotlin.Unit> {
Does anyone have an idea why this is happening and whose "fault" it is?
Should I report this to Kotlin or Gradle?
Is there a generic work-around besides changing every case that fails at runtime to .artifactsGetter(Action { ... })
instead of .artifactsGetter { ... }
?
(With Gradle 7.6.4 and thus KGP 1.7.10 it worked fine as long as the language version stayed at 1.4, but started to fail when I set it to 1.7, with Gradle 8.6 and thus KGP 1.9.20 it even fails with language version 1.4)edrd
03/14/2024, 3:48 PMAction
, shouldn’t it? At least is that how I thought SAM conversions worked.Vampire
03/14/2024, 3:52 PMVampire
03/14/2024, 4:01 PM