Hey, I can't find a solution compatible with confi...
# community-support
m
Hey, I can't find a solution compatible with configuration cache. I have a standalone gradle.kts file that contains a task. This task makes use of the top level function declared in the same file. From reading the logs this causes issues as to know of this function Gradle tries to serialize the Project and that's not supported by design. What's the solution here?
One solution I found is to place related functions directly in to the body of a task before action. But I don't find this convenient as it makes the order of the functions strict
v
If you have functions in your build scripts, this is a strong sign, that you have too much imperative logic in your build scripts, and should maybe consider using convention plugins instead. The problem with the function regarding CC is, that the function is defined on the script instance so to access the function you would need a reference to the script instance in CC and that is not allowed. If you really want to have it directly in the build script, move the function to a object you declare in the buildscript, this makes it "static" and independent from the build script instance and should then be callable CC compatible.
e
just to check, what do you mean by "standalone gradle.kts"? if it's a script you're applying to other build scripts, you should migrate it to a plugin - and then you can move the top-level function to a regular .kt file and it'll all work
v
Well, the same for both, whether he just means a regular build script or a legacy script plugin. 🙂