Is the Kotlin Gradle plugin supposed to support Gr...
# gradle
e
Is the Kotlin Gradle plugin supposed to support Gradle configuration cache? And if yes, since which version?
👌 1
m
FWIW, we use it with 2.0.0-RC2. I think 1.9.20 was OK as well but can’t remember for sure
e
Thanks Martin, is that on Apollo KMP?
m
Yep
gratitude thank you 1
a
KGP 1.9.0 supported CC for KMP https://kotlinlang.org/docs/whatsnew19.html#preview-of-the-gradle-configuration-cache IIRC
kotlin("jvm")
+ CC worked in earlier versions?
e
Thanks Adam. I've turned it on and I'm getting a couple errors during import. Will share after lunch.
m
We’ve been hit for a while with errors that were due from other plugins but somewhat showed up in the report for KGP
e
It might be a similar issue, mine is for the JS tasks tho.
A messy error message:
* What went wrong:
Configuration cache state could not be cached: field
apiConfiguration
of
org.jetbrains.kotlin.gradle.plugin.mpp.compilationImpl.DefaultKotlinCompilationConfigurationsContainer
bean found in field
dependencyConfigurations
of
org.jetbrains.kotlin.gradle.plugin.mpp.compilationImpl.KotlinCompilationImpl$Params
bean found in field
params
of
org.jetbrains.kotlin.gradle.plugin.mpp.compilationImpl.KotlinCompilationImpl
bean found in field
this$0
of
org.jetbrains.kotlin.gradle.plugin.mpp.compilationImpl.KotlinCompilationImpl$associateWith$2
bean found in field
forAllActions
of
org.jetbrains.kotlin.gradle.utils.MutableObservableSetImpl
bean found in field
allAssociatedCompilationsImpl
of
org.jetbrains.kotlin.gradle.plugin.mpp.compilationImpl.KotlinCompilationImpl
bean found in field
$$delegate_0
of
org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJvmCompilation
bean found in field
map
of
org.gradle.api.internal.DefaultNamedDomainObjectCollection$UnfilteredIndex
bean found in field
index
of
org.gradle.api.internal.FactoryNamedDomainObjectContainer
bean found in field
compilations
of
org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget
bean found in field
target
of
org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJvmCompilation
bean found in field
underlying
of
org.jetbrains.kotlin.gradle.utils.MutableObservableSetImpl
bean found in field
compilations
of
org.jetbrains.kotlin.gradle.plugin.sources.DefaultKotlinSourceSet
bean found in field
underlying
of
org.jetbrains.kotlin.gradle.utils.MutableObservableSetImpl
bean found in field
dependsOnClosureImpl
of
org.jetbrains.kotlin.gradle.plugin.sources.DefaultKotlinSourceSet
bean found in field
value
of
org.jetbrains.kotlin.tooling.core.Extras$Entry
bean found in field
extras
of
org.jetbrains.kotlin.tooling.core.MutableExtrasImpl
bean found in field
extras
of
org.jetbrains.kotlin.gradle.plugin.mpp.compilationImpl.KotlinCompilationImpl
bean found in field
$$delegate_0
of
org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrCompilation
bean found in field
compilation
of
org.jetbrains.kotlin.gradle.targets.js.npm.resolver.KotlinCompilationNpmResolver
bean found in field
byCompilation
of
org.jetbrains.kotlin.gradle.targets.js.npm.resolver.KotlinProjectNpmResolver
bean found in field
projectResolvers
of
org.jetbrains.kotlin.gradle.targets.js.npm.resolver.KotlinRootNpmResolver
bean found in field
resolver
of
org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
bean found in field
nodeJs
of
org.jetbrains.kotlin.gradle.targets.js.ir.KotlinBrowserJsIr
bean found in field
value
of
kotlin.InitializedLazyImpl
bean found in field
browser$delegate
of
org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget
bean found in field
this$0
of
org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget$commonLazy$2$1$1
bean found in field
val$action
of
org.gradle.internal.code.DefaultUserCodeApplicationContext$CurrentApplication$1
bean found in field
delegate
of
org.gradle.api.internal.DefaultCollectionCallbackActionDecorator$BuildOperationEmittingAction
bean found in field
val$action
of
org.gradle.api.internal.collections.CollectionFilter$1
bean found in field
multipleActions
of
org.gradle.internal.ImmutableActionSet$SetWithManyActions
bean found in field
addActions
of
org.gradle.api.internal.collections.DefaultCollectionEventRegister
bean found in field
eventRegister
of
org.gradle.api.internal.DefaultDomainObjectSet
bean found in field
$$delegate_0
of
org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsBinaryContainer
bean found in field
binaries
of
org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrCompilation
bean found in field
compilation
of
org.jetbrains.kotlin.gradle.targets.js.ir.Library
bean found in field
$this_configureEach
of
com.hcl.mainframe.project.gradle.plugins.ProjectModuleExtension$js$3$3$1$2
bean found in field
action
of
org.gradle.api.internal.AbstractTask$TaskActionWrapper
bean found in field
actions
of task
:faproto:compileProductionLibraryKotlinJs
of type `org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrLink`: error writing value of type 'org.gradle.api.internal.artifacts.configurations.DefaultUnlockedConfiguration'
> Resolving dependency configuration 'jvmTestCompilationApi' is not allowed as it is defined as 'canBeResolved=false'.
Instead, a resolvable ('canBeResolved=true') dependency configuration that extends 'jvmTestCompilationApi' should be resolved.
I found this comment mentioning
DefaultUnlockedConfiguration
v
From the error, I'd say in
com.hcl.mainframe.project.gradle.plugins.ProjectModuleExtension
you do a
doLast
or
doFirst
on the
compileProductionLibraryKotlinJs
task within which you use the
apiConfiguration
configuration
Or rather, you do not use
apiConfiguration
but you use
compilation
that then through a long chain has
apiConfiguration
as a property which just happens to be the first CC-incompatible field found
e
@Vampire indeed! I use
doLast
Copy code
binaries.withType<JsIrBinary>().configureEach {
  linkTask.configure {
    // Some other code

    doLast {
      // If we are generating TypeScript declarations, we also want to be
      // able to extend the TypeScript types from the TypeScript world.
      // By default, types are marked "unique", so we need to get rid of
      // those unique symbols
      if (generateTs) {
        val typesFileName = "${project.name}.d.ts"
        val typesFile = destinationDirectory.file(typesFileName).get()
        updateTypeScriptTypes(typesFile.asFile)
      }
    }
  }
}
Damn, I'm not sure how you manage to understand it, and I'm even more unsure how to "fix" it lol
v
You probably have multiple problems there. If the cache storing would have worked, it would then complain that you must not use
project
at execution time which you do.
That you could for example mitigate by
val projectName = project.name
before the
doLast
and only using
projectName
in the
doLast
The cache storage is because of something else you refer to. Maybe the
updateTypeScriptTypes
or the
destinationDirectory
. Hard to say for me from that snippet.
e
Indeed I use a lot the
project
property in my plugins. So even if I fix it there, it might pop up in other places. I've removed the
doLast
as a test and now I get
Copy code
> Invocation of 'Task.project' by task ':types-linkedom:compileProductionLibraryKotlinJs' at execution time is unsupported.
> Invocation of 'Task.project' by task ':parsers:compileProductionLibraryKotlinJs' at execution time is unsupported.
> Invocation of 'Task.project' by task ':zproto:compileProductionLibraryKotlinJs' at execution time is unsupported.
As you had predicted!
👌 1
v
Damn, I'm not sure how you manage to understand it,
I formatted it. 🙂 Easier would have been to just look at the CC report where you have it already nicely formatted as tree. But just formatting your error a bit yields
Copy code
Configuration cache state could not be cached:
field `apiConfiguration` of `org.jetbrains.kotlin.gradle.plugin.mpp.compilationImpl.DefaultKotlinCompilationConfigurationsContainer` bean 
found in field `dependencyConfigurations` of `org.jetbrains.kotlin.gradle.plugin.mpp.compilationImpl.KotlinCompilationImpl$Params` bean 
found in field `params` of `org.jetbrains.kotlin.gradle.plugin.mpp.compilationImpl.KotlinCompilationImpl` bean 
found in field `this$0` of `org.jetbrains.kotlin.gradle.plugin.mpp.compilationImpl.KotlinCompilationImpl$associateWith$2` bean 
found in field `forAllActions` of `org.jetbrains.kotlin.gradle.utils.MutableObservableSetImpl` bean 
found in field `allAssociatedCompilationsImpl` of `org.jetbrains.kotlin.gradle.plugin.mpp.compilationImpl.KotlinCompilationImpl` bean 
found in field `$$delegate_0` of `org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJvmCompilation` bean 
found in field `map` of `org.gradle.api.internal.DefaultNamedDomainObjectCollection$UnfilteredIndex` bean 
found in field `index` of `org.gradle.api.internal.FactoryNamedDomainObjectContainer` bean 
found in field `compilations` of `org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget` bean 
found in field `target` of `org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJvmCompilation` bean 
found in field `underlying` of `org.jetbrains.kotlin.gradle.utils.MutableObservableSetImpl` bean 
found in field `compilations` of `org.jetbrains.kotlin.gradle.plugin.sources.DefaultKotlinSourceSet` bean 
found in field `underlying` of `org.jetbrains.kotlin.gradle.utils.MutableObservableSetImpl` bean 
found in field `dependsOnClosureImpl` of `org.jetbrains.kotlin.gradle.plugin.sources.DefaultKotlinSourceSet` bean 
found in field `value` of `org.jetbrains.kotlin.tooling.core.Extras$Entry` bean found in 
field `extras` of `org.jetbrains.kotlin.tooling.core.MutableExtrasImpl` bean found in 
field `extras` of `org.jetbrains.kotlin.gradle.plugin.mpp.compilationImpl.KotlinCompilationImpl` bean 
found in field `$$delegate_0` of `org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrCompilation` bean 
found in field `compilation` of `org.jetbrains.kotlin.gradle.targets.js.npm.resolver.KotlinCompilationNpmResolver` bean 
found in field `byCompilation` of `org.jetbrains.kotlin.gradle.targets.js.npm.resolver.KotlinProjectNpmResolver` bean 
found in field `projectResolvers` of `org.jetbrains.kotlin.gradle.targets.js.npm.resolver.KotlinRootNpmResolver` bean 
found in field `resolver` of `org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension` bean 
found in field `nodeJs` of `org.jetbrains.kotlin.gradle.targets.js.ir.KotlinBrowserJsIr` bean 
found in field `value` of `kotlin.InitializedLazyImpl` bean 
found in field `browser$delegate` of `org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget` bean 
found in field `this$0` of `org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget$commonLazy$2$1$1` bean 
found in field `val$action` of `org.gradle.internal.code.DefaultUserCodeApplicationContext$CurrentApplication$1` bean 
found in field `delegate` of `org.gradle.api.internal.DefaultCollectionCallbackActionDecorator$BuildOperationEmittingAction` bean 
found in field `val$action` of `org.gradle.api.internal.collections.CollectionFilter$1` bean 
found in field `multipleActions` of `org.gradle.internal.ImmutableActionSet$SetWithManyActions` bean 
found in field `addActions` of `org.gradle.api.internal.collections.DefaultCollectionEventRegister` bean 
found in field `eventRegister` of `org.gradle.api.internal.DefaultDomainObjectSet` bean 
found in field `$$delegate_0` of `org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsBinaryContainer` bean 
found in field `binaries` of `org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrCompilation` bean 
found in field `compilation` of `org.jetbrains.kotlin.gradle.targets.js.ir.Library` bean 
found in field `$this_configureEach` of `com.hcl.mainframe.project.gradle.plugins.ProjectModuleExtension$js$3$3$1$2` bean 
found in field `action` of `org.gradle.api.internal.AbstractTask$TaskActionWrapper` bean 
found in field `actions` of task `:faproto:compileProductionLibraryKotlinJs` of type `org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrLink`: error writing value of type 'org.gradle.api.internal.artifacts.configurations.DefaultUnlockedConfiguration'
> Resolving dependency configuration 'jvmTestCompilationApi' is not allowed as it is defined as 'canBeResolved=false'.
  Instead, a resolvable ('canBeResolved=true') dependency configuration that extends 'jvmTestCompilationApi' should be resolved.
Where you see in the bottom lines that the problem stems from an action that you add in the
configureEach
of said extension
gratitude thank you 1
Actually, while thinking about it, it is probably not even the code within the
doLast
but you refer to
compilation
outside the
doLast
within the
configureEach
, which then makes the
compilation
being a "field" of the "class" that represents the
configureEach
closure and within the
doLast
you refer to something else defined in
configureEach
. Due to that to store the
doLast
action it tries to serialize the instance of the
configureEach
closure to access the field which then tries to serialize the
compilation
too and that is which then fails in the end.
It's sometimes a bit hard to find the actual culprit unfortunately
But that is what Martin tried to say, independent of whether it is a JS task or some other task. Just that it complains about a KMP task does not mean it is a problem of the KMP implementation, but could be some other plugin or even your build script causing it.
e
Probably trying to incrementally remove parts of the code might help in revealing where it breaks
👌 1
1. Remove * all * of my plugin code 2. Gradle: still complains I desist 😂
gradle intensifies 2
v
No, don't desist. Find out who the culprit is now and report, or it cannot get fixed. 🙂 Or maybe you also do something in the build script that is incompatible. A
--stacktrace
or
--scan
or CC report file should hopefully help.