public class ExternalToolProxyClassLoader
extends java.net.URLClassLoader
This class loader is a solution to the following problem: a Gradle plugin or task uses an external tool and allows the exact version of that tool to be specified at runtime, e.g. through a configuration property. To achieve this, the external tool classes must be loaded from a dynamically specified location. This means that the classes of the plugin or task that uses the tool cannot reference the external tool classes directly, since that would trigger loading the external tool classes when the plugin/task classes are loaded, which would occur before the plugin/task has a chance to specify the location of the external tool.
Instead, the external tool classes are referenced only through a special proxy class that encapsulates the functionality of the tool and exposes the result as types not defined in the tool classes, e.g. standard JDK or Gradle types.
To further complicate things, some external tools may be loaded by the class loader that loaded
the plugin/task classes for other reasons than being accessed by the plugin/task. For example, if
the external tool is Maven, and the built-in maven plugin is applied to the build script,
the Maven classes may be loaded before the plugin/task attempts to load them, and may be of the
wrong version.
The external tool classes must therefore be loaded by another class loader than the one that loaded the plugin/task that uses them. The proxy class must also be loaded by this class loader, since it references the tool classes, and loading it will trigger loading the external tool classes. But the proxy class provides the interface to the Gradle plugin or task that uses the external tool, so it must somehow be available to the plugin/task. This is solved by having the proxy class implement an interface that the plugin/task uses. The implementation of the interface, i.e. the proxy class, is then loaded dynamically wit the class loader that also loads the external tool classes.
To summarize, this class loader should:
ClassCastException will be thrown)| Modifier and Type | Method and Description |
|---|---|
protected java.lang.Class<?> |
loadClass(java.lang.String pName,
boolean pResolve) |
addURL, close, definePackage, findClass, findResource, findResources, getPermissions, getResourceAsStream, getURLs, newInstance, newInstanceclearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findSystemClass, getClassLoadingLock, getPackage, getPackages, getParent, getResource, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, registerAsParallelCapable, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners