Martin
07/02/2025, 12:12 PMVampire
07/02/2025, 12:42 PMVladimir Sitnikov
07/02/2025, 1:28 PMMartin
07/02/2025, 1:30 PMMartin
07/02/2025, 1:30 PMThomas Broyer
07/02/2025, 1:30 PMVampire
07/02/2025, 2:36 PMFor tasks that are using isolated workers, this feels like unnecessary invalidation. The workers have very constrained input/outputs and do not share the classpath with the rest of the build so they probably do not need to be recomputed when the build script classpath changes.I don't think this is true. If the class path is not available in the worker, the work action would also not be available and thus could not be executed.
Sadly, it's also fragile because any change in the buildscript classpath ends up changing most (all of?) the cache keys.Depends. For built-in tasks for example it should not invalidate the cache key, because their classpath did not change unless you changed the Gradle version or added custom task actions.
Martin
07/02/2025, 2:42 PMVampire
07/02/2025, 2:44 PMI guess where I'm going with this is that there "should" be a way to make this possible (do work that is completely isolated from the rest of the build).For that you would inject
ExecOperations
and use javaExec
on it. There you completely control the classpath and the process is not reused.
Even with process-isolation the worker processes are reused if possible so are not enough for use-cases where static state is involved and the problemVampire
07/02/2025, 2:45 PMHow is the classpath of a task computed? I have never really understood that part. Is Gradle able to look up the jar where a given task is defined (easy) and all its referenced jars (harder)?I don't fully remember, quite some time I looked into that last. But I guess it takes the class of all actions and gets the classloader hierarchy of that. Thus if you have a built-in task only the Gradle stuff is in the classpath and thus the task should get the same cache-key
Martin
07/02/2025, 2:47 PMMartin
07/02/2025, 2:48 PMimplementation
in your build-logic
included build, they will probably all belong to the same classloader.Martin
07/02/2025, 2:50 PMbuild-logic
runtime classpath will invalidate all of KGP and AGP and 90% of your build (but not the built-in Gradle tasks)Vampire
07/02/2025, 2:57 PMThomas Broyer
07/02/2025, 3:56 PMcompileOnly
dependency that will then be provided at runtime to the worker API, then the work action should only depend on your WorkParameter, and everything else will come from the runtime-configured classpath.Vampire
07/02/2025, 10:13 PM