You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2019/01/26 15:19:12 UTC

[maven-javadoc-plugin] branch MJAVADOC-568 created (now 183c1fe)

This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a change to branch MJAVADOC-568
in repository https://gitbox.apache.org/repos/asf/maven-javadoc-plugin.git.


      at 183c1fe  javadoc:jar fails when project has Automatic-Module-Name and (implicit) uses offlinelinks with element-list

This branch includes the following new commits:

     new 183c1fe  javadoc:jar fails when project has Automatic-Module-Name and (implicit) uses offlinelinks with element-list

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[maven-javadoc-plugin] 01/01: javadoc:jar fails when project has Automatic-Module-Name and (implicit) uses offlinelinks with element-list

Posted by rf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a commit to branch MJAVADOC-568
in repository https://gitbox.apache.org/repos/asf/maven-javadoc-plugin.git

commit 183c1fe6be504416cbddbb7d671555f70833cd56
Author: rfscholte <rf...@apache.org>
AuthorDate: Sat Jan 26 14:18:07 2019 +0100

    javadoc:jar fails when project has Automatic-Module-Name and (implicit) uses offlinelinks with element-list
---
 pom.xml                                            |   2 +-
 .../projects/MJAVADOC-567_aggr-mixed/verify.groovy |   2 +-
 .../MJAVADOC-568_jar-mixed/invoker.properties      |  18 +++
 .../MJAVADOC-568_jar-mixed/module1/pom.xml         |  49 ++++++
 .../module1/src/main/java/module-info.java}        |  18 +--
 .../module1/src/main/java/module1/Module1.java}    |  18 +--
 .../MJAVADOC-568_jar-mixed/module2/pom.xml         |  69 +++++++++
 .../module2/src/main/java/module2/Module2.java}    |  22 ++-
 src/it/projects/MJAVADOC-568_jar-mixed/pom.xml     |  65 ++++++++
 .../maven/plugins/javadoc/AbstractJavadocMojo.java | 170 +++++++++++++++++----
 10 files changed, 360 insertions(+), 73 deletions(-)

diff --git a/pom.xml b/pom.xml
index 4a21374..87275ed 100644
--- a/pom.xml
+++ b/pom.xml
@@ -240,7 +240,7 @@ under the License.
     <dependency>
       <groupId>org.codehaus.plexus</groupId>
       <artifactId>plexus-java</artifactId>
-      <version>1.0.1</version>
+      <version>1.0.2</version>
     </dependency>
     <dependency>
       <groupId>org.codehaus.plexus</groupId>
diff --git a/src/it/projects/MJAVADOC-567_aggr-mixed/verify.groovy b/src/it/projects/MJAVADOC-567_aggr-mixed/verify.groovy
index 2627dc1..d1e34c5 100644
--- a/src/it/projects/MJAVADOC-567_aggr-mixed/verify.groovy
+++ b/src/it/projects/MJAVADOC-567_aggr-mixed/verify.groovy
@@ -25,7 +25,7 @@ def expectedLines = ['Creating an aggregated report for both named and unnamed m
                      ' - testcase:module2']
 
 def errorLines = buildLog.readLines() 
-                         .dropWhile{ !it.startsWith('[ERROR]') }
+                         .dropWhile{ !it.startsWith('[ERROR] Creating') }
                          .takeWhile{ it.startsWith('[ERROR]') }
                          .collect  { it - '[ERROR] '}
                          
diff --git a/src/it/projects/MJAVADOC-568_jar-mixed/invoker.properties b/src/it/projects/MJAVADOC-568_jar-mixed/invoker.properties
new file mode 100644
index 0000000..538618d
--- /dev/null
+++ b/src/it/projects/MJAVADOC-568_jar-mixed/invoker.properties
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+invoker.java.version = 9+
+invoker.goals = package
\ No newline at end of file
diff --git a/src/it/projects/MJAVADOC-568_jar-mixed/module1/pom.xml b/src/it/projects/MJAVADOC-568_jar-mixed/module1/pom.xml
new file mode 100644
index 0000000..985d205
--- /dev/null
+++ b/src/it/projects/MJAVADOC-568_jar-mixed/module1/pom.xml
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied.  See the License for the
+  specific language governing permissions and limitations
+  under the License.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.maven.plugins.javadoc.it</groupId>
+    <artifactId>mjavadoc568</artifactId>
+    <version>1.0-SNAPSHOT</version>
+  </parent>
+  <artifactId>mjavadoc568-module1</artifactId>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-javadoc-plugin</artifactId>
+        <executions>
+          <execution>
+            <id>attach-javadocs</id>
+            <goals>
+              <goal>jar</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+</project>
\ No newline at end of file
diff --git a/src/it/projects/MJAVADOC-567_aggr-mixed/verify.groovy b/src/it/projects/MJAVADOC-568_jar-mixed/module1/src/main/java/module-info.java
similarity index 53%
copy from src/it/projects/MJAVADOC-567_aggr-mixed/verify.groovy
copy to src/it/projects/MJAVADOC-568_jar-mixed/module1/src/main/java/module-info.java
index 2627dc1..1fb7d2b 100644
--- a/src/it/projects/MJAVADOC-567_aggr-mixed/verify.groovy
+++ b/src/it/projects/MJAVADOC-568_jar-mixed/module1/src/main/java/module-info.java
@@ -1,3 +1,4 @@
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -16,17 +17,8 @@
  * specific language governing permissions and limitations
  * under the License.
  */
- 
-def buildLog = new File(basedir,'build.log')
-
-def expectedLines = ['Creating an aggregated report for both named and unnamed modules is not possible.',
-                     'Ensure that every module has a module descriptor or is a jar with a MANIFEST.MF containing an Automatic-Module-Name.',
-                     'Fix the following projects:',
-                     ' - testcase:module2']
 
-def errorLines = buildLog.readLines() 
-                         .dropWhile{ !it.startsWith('[ERROR]') }
-                         .takeWhile{ it.startsWith('[ERROR]') }
-                         .collect  { it - '[ERROR] '}
-                         
-assert expectedLines == errorLines                   
+module module1
+{
+	exports module1;
+}
\ No newline at end of file
diff --git a/src/it/projects/MJAVADOC-567_aggr-mixed/verify.groovy b/src/it/projects/MJAVADOC-568_jar-mixed/module1/src/main/java/module1/Module1.java
similarity index 53%
copy from src/it/projects/MJAVADOC-567_aggr-mixed/verify.groovy
copy to src/it/projects/MJAVADOC-568_jar-mixed/module1/src/main/java/module1/Module1.java
index 2627dc1..b71b7f9 100644
--- a/src/it/projects/MJAVADOC-567_aggr-mixed/verify.groovy
+++ b/src/it/projects/MJAVADOC-568_jar-mixed/module1/src/main/java/module1/Module1.java
@@ -1,3 +1,5 @@
+package module1;
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -16,17 +18,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
- 
-def buildLog = new File(basedir,'build.log')
-
-def expectedLines = ['Creating an aggregated report for both named and unnamed modules is not possible.',
-                     'Ensure that every module has a module descriptor or is a jar with a MANIFEST.MF containing an Automatic-Module-Name.',
-                     'Fix the following projects:',
-                     ' - testcase:module2']
 
-def errorLines = buildLog.readLines() 
-                         .dropWhile{ !it.startsWith('[ERROR]') }
-                         .takeWhile{ it.startsWith('[ERROR]') }
-                         .collect  { it - '[ERROR] '}
-                         
-assert expectedLines == errorLines                   
+public final class Module1
+{
+}
diff --git a/src/it/projects/MJAVADOC-568_jar-mixed/module2/pom.xml b/src/it/projects/MJAVADOC-568_jar-mixed/module2/pom.xml
new file mode 100644
index 0000000..f3f619f
--- /dev/null
+++ b/src/it/projects/MJAVADOC-568_jar-mixed/module2/pom.xml
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied.  See the License for the
+  specific language governing permissions and limitations
+  under the License.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.maven.plugins.javadoc.it</groupId>
+    <artifactId>mjavadoc568</artifactId>
+    <version>1.0-SNAPSHOT</version>
+  </parent>
+  <artifactId>mjavadoc568-module2</artifactId>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-jar-plugin</artifactId>
+        <version>2.3.2</version>
+        <configuration>
+          <archive>
+            <manifestEntries>
+              <Automatic-Module-Name>mjavadoc568.module2</Automatic-Module-Name>
+            </manifestEntries>
+          </archive>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-javadoc-plugin</artifactId>
+        <executions>
+          <execution>
+            <id>attach-javadocs</id>
+            <goals>
+              <goal>jar</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.maven.plugins.javadoc.it</groupId>
+      <artifactId>mjavadoc568-module1</artifactId>
+      <version>1.0-SNAPSHOT</version>
+    </dependency>
+  </dependencies>
+</project>
\ No newline at end of file
diff --git a/src/it/projects/MJAVADOC-567_aggr-mixed/verify.groovy b/src/it/projects/MJAVADOC-568_jar-mixed/module2/src/main/java/module2/Module2.java
similarity index 53%
copy from src/it/projects/MJAVADOC-567_aggr-mixed/verify.groovy
copy to src/it/projects/MJAVADOC-568_jar-mixed/module2/src/main/java/module2/Module2.java
index 2627dc1..a34c5d7 100644
--- a/src/it/projects/MJAVADOC-567_aggr-mixed/verify.groovy
+++ b/src/it/projects/MJAVADOC-568_jar-mixed/module2/src/main/java/module2/Module2.java
@@ -1,3 +1,5 @@
+package module2;
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -16,17 +18,13 @@
  * specific language governing permissions and limitations
  * under the License.
  */
- 
-def buildLog = new File(basedir,'build.log')
 
-def expectedLines = ['Creating an aggregated report for both named and unnamed modules is not possible.',
-                     'Ensure that every module has a module descriptor or is a jar with a MANIFEST.MF containing an Automatic-Module-Name.',
-                     'Fix the following projects:',
-                     ' - testcase:module2']
+import module1.Module1;
 
-def errorLines = buildLog.readLines() 
-                         .dropWhile{ !it.startsWith('[ERROR]') }
-                         .takeWhile{ it.startsWith('[ERROR]') }
-                         .collect  { it - '[ERROR] '}
-                         
-assert expectedLines == errorLines                   
+public final class Module2
+{
+    public Module1 getModule1()
+    {
+        return new Module1();
+    }
+}
diff --git a/src/it/projects/MJAVADOC-568_jar-mixed/pom.xml b/src/it/projects/MJAVADOC-568_jar-mixed/pom.xml
new file mode 100644
index 0000000..a50c54f
--- /dev/null
+++ b/src/it/projects/MJAVADOC-568_jar-mixed/pom.xml
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied.  See the License for the
+  specific language governing permissions and limitations
+  under the License.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.maven.plugins.javadoc.it</groupId>
+  <artifactId>mjavadoc568</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <packaging>pom</packaging>
+
+  <url>https://com.foo.bar</url>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+
+  <build>
+    <pluginManagement>
+      <plugins>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-compiler-plugin</artifactId>
+          <version>3.8.0</version>
+          <configuration>
+            <release>9</release>
+          </configuration>
+        </plugin>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-jar-plugin</artifactId>
+          <version>3.0.0</version>
+        </plugin>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-javadoc-plugin</artifactId>
+          <version>3.1.0-SNAPSHOT</version>
+        </plugin>
+      </plugins>
+    </pluginManagement>
+  </build>
+  <modules>
+    <module>module1</module>
+    <module>module2</module>
+  </modules>
+</project>
\ No newline at end of file
diff --git a/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java b/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
index b7f7308..4ddab70 100644
--- a/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
+++ b/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
@@ -84,7 +84,9 @@ import org.codehaus.plexus.archiver.manager.NoSuchArchiverException;
 import org.codehaus.plexus.components.io.fileselectors.IncludeExcludeFileSelector;
 import org.codehaus.plexus.languages.java.jpms.JavaModuleDescriptor;
 import org.codehaus.plexus.languages.java.jpms.LocationManager;
+import org.codehaus.plexus.languages.java.jpms.ModuleNameSource;
 import org.codehaus.plexus.languages.java.jpms.ResolvePathRequest;
+import org.codehaus.plexus.languages.java.jpms.ResolvePathResult;
 import org.codehaus.plexus.languages.java.jpms.ResolvePathsRequest;
 import org.codehaus.plexus.languages.java.jpms.ResolvePathsResult;
 import org.codehaus.plexus.languages.java.version.JavaVersion;
@@ -304,6 +306,8 @@ public abstract class AbstractJavadocMojo
     @Component
     private ToolchainManager toolchainManager;
 
+    final LocationManager locationManager = new LocationManager();
+
     // ----------------------------------------------------------------------
     // Mojo parameters
     // ----------------------------------------------------------------------
@@ -2046,27 +2050,37 @@ public abstract class AbstractJavadocMojo
             }
         }
 
-        List<String> arguments = new ArrayList<>();
-
-        // ----------------------------------------------------------------------
-        // Wrap Javadoc options
-        // ----------------------------------------------------------------------
-
-        addJavadocOptions( javadocOutputDirectory, arguments, sourcePaths );
-
         // ----------------------------------------------------------------------
         // Wrap Standard doclet Options
         // ----------------------------------------------------------------------
+        List<String> standardDocletArguments = new ArrayList<>();
 
+        Set<OfflineLink> offlineLinks;
         if ( StringUtils.isEmpty( doclet ) || useStandardDocletOptions )
         {
-            addStandardDocletOptions( javadocOutputDirectory, arguments );
+            offlineLinks = getLinkofflines();
+            addStandardDocletOptions( javadocOutputDirectory, standardDocletArguments, offlineLinks );
+        }
+        else
+        {
+            offlineLinks = Collections.emptySet();
         }
 
         // ----------------------------------------------------------------------
+        // Wrap Javadoc options
+        // ----------------------------------------------------------------------
+        List<String> javadocArguments = new ArrayList<>();
+
+        addJavadocOptions( javadocOutputDirectory, javadocArguments, sourcePaths, offlineLinks );
+
+        // ----------------------------------------------------------------------
         // Write options file and include it in the command line
         // ----------------------------------------------------------------------
 
+        List<String> arguments = new ArrayList<>( javadocArguments.size() + standardDocletArguments.size() );
+        arguments.addAll( javadocArguments );
+        arguments.addAll( standardDocletArguments );
+
         if ( arguments.size() > 0 )
         {
             addCommandLineOptions( cmd, arguments, javadocOutputDirectory );
@@ -4045,13 +4059,9 @@ public abstract class AbstractJavadocMojo
      * @see #getModulesLinks()
      * @see <a href="http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javadoc.html#package-list">package-list spec</a>
      */
-    private void addLinkofflineArguments( List<String> arguments )
+    private void addLinkofflineArguments( List<String> arguments, Set<OfflineLink> offlineLinksList )
         throws MavenReportException
     {
-        Set<OfflineLink> offlineLinksList = collectOfflineLinks();
-
-        offlineLinksList.addAll( getModulesLinks() );
-
         for ( OfflineLink offlineLink : offlineLinksList )
         {
             String url = offlineLink.getUrl();
@@ -4075,6 +4085,15 @@ public abstract class AbstractJavadocMojo
         }
     }
 
+    private Set<OfflineLink> getLinkofflines() throws MavenReportException
+    {
+        Set<OfflineLink> offlineLinksList = collectOfflineLinks();
+
+        offlineLinksList.addAll( getModulesLinks() );
+
+        return offlineLinksList;
+    }
+
     /**
      * Convenience method to process {@link #links} values as individual <code>-link</code> javadoc options.
      * If {@link #detectLinks}, try to add javadoc apidocs according Maven conventions for all dependencies given
@@ -4390,7 +4409,6 @@ public abstract class AbstractJavadocMojo
         {
             return returnList;
         }
-        LocationManager locationManager = new LocationManager();
 
         for ( Collection<Path> artifactSourcePaths: allSourcePaths.values() )
         {
@@ -4830,7 +4848,8 @@ public abstract class AbstractJavadocMojo
      */
     private void addJavadocOptions( File javadocOutputDirectory,
                                     List<String> arguments,
-                                    Map<String, Collection<Path>> allSourcePaths )
+                                    Map<String, Collection<Path>> allSourcePaths,
+                                    Set<OfflineLink> offlineLinks )
         throws MavenReportException
     {
         Collection<Path> sourcePaths = collect( allSourcePaths.values() );
@@ -4868,8 +4887,6 @@ public abstract class AbstractJavadocMojo
                                                            reactorProject.getArtifactId() ), reactorProject );
         }
         
-        final LocationManager locationManager = new LocationManager();
-        
         Collection<String> additionalModules = new ArrayList<>();
         
         boolean containsModuleDescriptor = false;
@@ -4888,13 +4905,13 @@ public abstract class AbstractJavadocMojo
             Collection<String> unnamedProjects = new ArrayList<>();
             for ( Map.Entry<String, Collection<Path>> projectSourcepaths : allSourcePaths.entrySet() )
             {
-                MavenProject aggregatorProject = reactorKeys.get( projectSourcepaths.getKey() );
-                if ( aggregatorProject != null )
+                MavenProject aggregatedProject = reactorKeys.get( projectSourcepaths.getKey() );
+                if ( aggregatedProject != null )
                 {
                     String moduleName = null;
                     
                     // Prefer jar over outputDirectory, since it may may contain an automatic module name
-                    File artifactFile = getArtifactFile( aggregatorProject );
+                    File artifactFile = getArtifactFile( aggregatedProject );
                     if ( artifactFile != null ) 
                     {
                         ResolvePathRequest<File> request = ResolvePathRequest.ofFile( artifactFile );
@@ -4986,23 +5003,83 @@ public abstract class AbstractJavadocMojo
             }
         }
 
-        Collection<Path> roots = new ArrayList<>();
-        for ( String path : getProjectSourceRoots( getProject() ) )
+
+        ResolvePathResult resolvePathResult = getResolvePathResult( getArtifactFile( getProject() ) );
+
+        // MJAVADOC-506 
+        File moduleDescriptorSource = null;
+        if ( resolvePathResult == null || resolvePathResult.getModuleNameSource() == ModuleNameSource.FILENAME )
         {
-            roots.add( Paths.get( path ) );
+            Collection<Path> roots = new ArrayList<>();
+            for ( String path : getProjectSourceRoots( getProject() ) )
+            {
+                roots.add( Paths.get( path ) );
+            }
+
+            moduleDescriptorSource = findMainDescriptor( roots );
         }
-        
-        File mainDescriptor = findMainDescriptor( roots );
 
-        if ( javadocRuntimeVersion.isAtLeast( "9" ) && ( isAggregator() || mainDescriptor != null ) && !isTest() )
+        boolean isExplicitModuleName =
+            resolvePathResult != null && ( resolvePathResult.getModuleNameSource() == ModuleNameSource.MODULEDESCRIPTOR
+                || resolvePathResult.getModuleNameSource() == ModuleNameSource.MANIFEST );
+
+        if ( javadocRuntimeVersion.isAtLeast( "9" )
+            && ( isAggregator() || isExplicitModuleName || moduleDescriptorSource != null ) 
+            && !isTest() )
         {
             ResolvePathsRequest<File> request =
-                ResolvePathsRequest.ofFiles( getPathElements() ).setAdditionalModules( additionalModules );
-            
-            if ( mainDescriptor != null )
+                ResolvePathsRequest.ofFiles( getPathElements() );
+
+            if ( moduleDescriptorSource != null )
+            {
+                request.setMainModuleDescriptor( moduleDescriptorSource );
+            }
+            else if ( resolvePathResult != null )
             {
-                request.setMainModuleDescriptor( mainDescriptor );
+                request.setModuleDescriptor( resolvePathResult.getModuleDescriptor() );
+            }
+
+            if ( resolvePathResult != null && resolvePathResult.getModuleNameSource() == ModuleNameSource.MANIFEST )
+            {
+                // represent --add-modules
+                List<String> addModules = new ArrayList<>();
+
+                // scan for element-list in offline links
+                for ( OfflineLink link : offlineLinks )
+                {
+                    if ( link.equals( getDefaultJavadocApiLink() ) )
+                    {
+                        continue;
+                    }
+
+                    Path elementList = Paths.get( link.getLocation(), "element-list" ); 
+                    if ( Files.isRegularFile( elementList ) )
+                    {
+                        try
+                        {
+                            List<String> lines = Files.readAllLines( elementList, StandardCharsets.UTF_8 );
+                            
+                            for ( String line : lines )
+                            {
+                                if ( line.startsWith( "module:" ) )
+                                {
+                                    addModules.add( line.substring( "module:".length() ) );
+                                }
+                            }
+                        }
+                        catch ( IOException e )
+                        {
+                            // noop
+                        }
+                    }
+                }
+                additionalModules.addAll( addModules );
+
+                String addModulesLine = StringUtils.join( addModules.iterator(), "," );
+                addArgIfNotEmpty( arguments, "--add-modules", JavadocUtil.quotedPathArgument( addModulesLine ) );
             }
+
+            request.setAdditionalModules( additionalModules );
             
             try
             {
@@ -5119,6 +5196,31 @@ public abstract class AbstractJavadocMojo
         }
     }
 
+    private ResolvePathResult getResolvePathResult( File artifactFile )
+    {
+        if ( artifactFile == null )
+        {
+            return null;
+        }
+
+        ResolvePathResult resolvePathResult = null;
+        ResolvePathRequest<File> resolvePathRequest = ResolvePathRequest.ofFile( artifactFile );
+        try
+        {
+            resolvePathResult = locationManager.resolvePath( resolvePathRequest );
+        }
+        catch ( IOException | RuntimeException /* e.g java.lang.module.FindException */ e )
+        {
+            Throwable cause = e;
+            while ( cause.getCause() != null )
+            {
+                cause = cause.getCause();
+            }
+            getLog().warn( e.getMessage() );
+        }
+        return resolvePathResult;
+    }
+
     private File findMainDescriptor( Collection<Path> roots )
     {
         for ( Path root : roots )
@@ -5144,7 +5246,9 @@ public abstract class AbstractJavadocMojo
      * @see <a href="http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javadoc.html#standard">
      *      http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javadoc.html#standard</a>
      */
-    private void addStandardDocletOptions( File javadocOutputDirectory, List<String> arguments )
+    private void addStandardDocletOptions( File javadocOutputDirectory, 
+                                           List<String> arguments,
+                                           Set<OfflineLink> offlineLinks )
         throws MavenReportException
     {
         validateStandardDocletOptions();
@@ -5191,7 +5295,7 @@ public abstract class AbstractJavadocMojo
 
         addLinkArguments( arguments );
 
-        addLinkofflineArguments( arguments );
+        addLinkofflineArguments( arguments, offlineLinks );
 
         addArgIf( arguments, linksource, "-linksource", SINCE_JAVADOC_1_4 );