From d676a758d7fe7993b41e483477ba4ab301a9d1cc Mon Sep 17 00:00:00 2001 From: Michael Osipov Date: Sun, 14 Jul 2024 23:15:18 +0200 Subject: [PATCH] [MJAVADOC-603] javadoc:fix failure on JDK10: java.lang.ClassNotFoundException: java.sql.Connection This closes #303 --- .../plugins/javadoc/AbstractFixJavadocMojo.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/apache/maven/plugins/javadoc/AbstractFixJavadocMojo.java b/src/main/java/org/apache/maven/plugins/javadoc/AbstractFixJavadocMojo.java index 7ef7968c7..a3be337a3 100644 --- a/src/main/java/org/apache/maven/plugins/javadoc/AbstractFixJavadocMojo.java +++ b/src/main/java/org/apache/maven/plugins/javadoc/AbstractFixJavadocMojo.java @@ -66,6 +66,7 @@ import com.thoughtworks.qdox.parser.ParseException; import com.thoughtworks.qdox.type.TypeResolver; import org.apache.commons.lang3.ClassUtils; +import org.apache.commons.lang3.reflect.MethodUtils; import org.apache.commons.text.StringEscapeUtils; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.DependencyResolutionRequiredException; @@ -79,6 +80,7 @@ import org.apache.maven.settings.Settings; import org.apache.maven.shared.invoker.MavenInvocationException; import org.codehaus.plexus.components.interactivity.InputHandler; +import org.codehaus.plexus.languages.java.version.JavaVersion; import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.ReaderFactory; import org.codehaus.plexus.util.StringUtils; @@ -201,6 +203,8 @@ public abstract class AbstractFixJavadocMojo extends AbstractMojo { */ private static final String CLIRR_MAVEN_PLUGIN_GOAL = "check"; + private static final JavaVersion JAVA_VERSION = JavaVersion.JAVA_SPECIFICATION_VERSION; + /** * Java Files Pattern. */ @@ -837,7 +841,17 @@ private ClassLoader getProjectClassLoader() throws MojoExecutionException { } } - projectClassLoader = new URLClassLoader(urls.toArray(new URL[urls.size()]), null); + ClassLoader parent = null; + if (JAVA_VERSION.isAtLeast("9")) { + try { + parent = (ClassLoader) MethodUtils.invokeMethod(ClassLoader.class, "getPlatformClassLoader"); + } catch (Exception e) { + throw new MojoExecutionException( + "Failed to invoke ClassLoader#getPlatformClassLoader() dynamically", e); + } + } + + projectClassLoader = new URLClassLoader(urls.toArray(new URL[urls.size()]), parent); } return projectClassLoader;