close the plugin classloader after finishing the job
This commit is contained in:
parent
419eedff5e
commit
d1c6163cb6
@ -169,9 +169,10 @@ public class Plugin extends AbstractMojo {
|
||||
|
||||
ClassLoader oldCL = Thread.currentThread().getContextClassLoader();
|
||||
|
||||
// [#2886] Add the surrounding project's dependencies to the current classloader
|
||||
URLClassLoader pluginClassLoader = getClassLoader();
|
||||
try {
|
||||
// [#2886] Add the surrounding project's dependencies to the current classloader
|
||||
Thread.currentThread().setContextClassLoader(getClassLoader());
|
||||
Thread.currentThread().setContextClassLoader(pluginClassLoader);
|
||||
|
||||
// [#5881] Target is allowed to be null
|
||||
if (generator.getTarget() == null)
|
||||
@ -201,12 +202,18 @@ public class Plugin extends AbstractMojo {
|
||||
// [#2886] Restore old class loader
|
||||
finally {
|
||||
Thread.currentThread().setContextClassLoader(oldCL);
|
||||
try {
|
||||
pluginClassLoader.close();
|
||||
}
|
||||
catch (Throwable e) { // catch all possible errors to avoid suppressing the original exception
|
||||
getLog().error("Couldn't close the classloader.", e);
|
||||
}
|
||||
}
|
||||
|
||||
project.addCompileSourceRoot(generator.getTarget().getDirectory());
|
||||
}
|
||||
|
||||
private ClassLoader getClassLoader() throws MojoExecutionException {
|
||||
private URLClassLoader getClassLoader() throws MojoExecutionException {
|
||||
try {
|
||||
List<String> classpathElements = project.getRuntimeClasspathElements();
|
||||
URL urls[] = new URL[classpathElements.size()];
|
||||
|
||||
Loading…
Reference in New Issue
Block a user