From d1c6163cb62169055afcf650d60dbe7b497de507 Mon Sep 17 00:00:00 2001 From: Sergey Tselovalnikov Date: Mon, 2 Jul 2018 15:44:42 +1000 Subject: [PATCH] close the plugin classloader after finishing the job --- .../main/java/org/jooq/codegen/maven/Plugin.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/jOOQ-codegen-maven/src/main/java/org/jooq/codegen/maven/Plugin.java b/jOOQ-codegen-maven/src/main/java/org/jooq/codegen/maven/Plugin.java index d1807a2ab5..5beb9d27b3 100644 --- a/jOOQ-codegen-maven/src/main/java/org/jooq/codegen/maven/Plugin.java +++ b/jOOQ-codegen-maven/src/main/java/org/jooq/codegen/maven/Plugin.java @@ -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 classpathElements = project.getRuntimeClasspathElements(); URL urls[] = new URL[classpathElements.size()];