Hey, I was playing around with configuration cache...
# gradle
b
Hey, I was playing around with configuration cache and it complained about this part in my `build.gradle.kts`:
Copy code
val openTelemetryJarFileName = "opentelemetry-javaagent-1.25.1.jar"
val copyOpenTelemetryJavaAgent by tasks.registering(Copy::class) {
    from(layout.projectDirectory.dir("resources/opentelemetry"))
    into(jibAppRoot)
    doLast {
        // Required for reproducible builds.
        jibAppRoot.file(openTelemetryJarFileName).asFile.setLastModified(0)
    }
}
cannot serialize Gradle script object references as these are not supported with the configuration cache.
I guess it does not like, that I am using a variable inside the task. How do I solve this? I am thinking about a task, that generates
opentelemetry-javaagent-1.25.1.jar
as output, which I can then (hopefully) use as input for the
copyOpenTelemetryJavaAgent
task
v
You are right about the assumption with the variable. As it is a top-level variable, it has a reference to the script instance which the CC does not like. If you just inside the configuration lambda, but outside the
doLast
do a
val openTelemetryJarFileName = openTelemetryJarFileName
that should fix it.
💡 1
b
Thing is: I need the fileName also in another task. That’s why it is a variable
v
And? I did not say move the variable, I said add that line additionally. 😉
b
ahhh. Alrighty. Will give it a try. Thank you 🙂
I got the error from my initial post only in CI. Do you happen to know, how to check for full configuration cache compatibility on my machine?
v
Well, you would need to execute all tasks with CC enabled. But if you get that error on CI and locally do
gw copyOpenTelemetryJavaAgent
with CC enabled, you should get the same error. Unless on CI there is maybe some init script further changing your build or similar.
gratitude thank you 1