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..a48d8d099 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.invokeStaticMethod(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;