When multiple builds are run in the same Gradle daemon if the rewrite classpath changes we'll create a new RewriteClassLoader, but the old one and all the classes it ever loaded never get garbage collected.
We load JGit within RewriteClassLoader to keep it isolated from the rest of the plugin classpath. But JGit registers a shutdown hook in a static initializer. So that holds a reference to the classloader until the end of the JVM.
This becomes a problem only when you do multiple builds on the same Gradle daemon with different classpaths.
This shutdown hook is registered in a static initializer in org.eclipse.jgit.util.FS:
We can't load this class from the parent classloader because it's shaded into rewrite-core.
To fix this we have to do something like:
Run in a separate process
Fork JGit / use a modified class file for that one class that does not register the shutdown hook
When multiple builds are run in the same Gradle daemon if the rewrite classpath changes we'll create a new
RewriteClassLoader
, but the old one and all the classes it ever loaded never get garbage collected.We load JGit within RewriteClassLoader to keep it isolated from the rest of the plugin classpath. But JGit registers a shutdown hook in a static initializer. So that holds a reference to the classloader until the end of the JVM.
This becomes a problem only when you do multiple builds on the same Gradle daemon with different classpaths.
This shutdown hook is registered in a static initializer in org.eclipse.jgit.util.FS:
We can't load this class from the parent classloader because it's shaded into rewrite-core. To fix this we have to do something like: