Class RewriteClassLoader

All Implemented Interfaces:
Closeable, AutoCloseable

public class RewriteClassLoader extends URLClassLoader
Rewrite uses jackson for serialization/deserialization. So do lots of other build plugins. Gradle plugins all share the same classpath at runtime.

This classloader exists to isolate rewrite's use of jackson from the rest of the build.

  • Constructor Details

    • RewriteClassLoader

      public RewriteClassLoader(Collection<URL> artifacts)
  • Method Details

    • loadClass

      protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException
      Load the named class. We want classes that extend org.openrewrite.Recipe to be loaded by this ClassLoader only. But we want classes required to run recipes to continue to be loaded by their parent ClassLoader to avoid ClassCastExceptions.
      Overrides:
      loadClass in class ClassLoader
      Throws:
      ClassNotFoundException
    • shouldBeParentLoaded

      protected boolean shouldBeParentLoaded(String name)