Skip to content

Commit

Permalink
close the plugin classloader after finishing the job
Browse files Browse the repository at this point in the history
  • Loading branch information
SerCeMan committed Jul 2, 2018
1 parent 419eedf commit d1c6163
Showing 1 changed file with 10 additions and 3 deletions.
Expand Up @@ -169,9 +169,10 @@ public void execute() throws MojoExecutionException {

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)
Expand Down Expand Up @@ -201,12 +202,18 @@ public void execute() throws MojoExecutionException {
// [#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()];
Expand Down

0 comments on commit d1c6163

Please sign in to comment.