[MJAVADOC-555] Javadoc:aggregate, Javadoc:jar fail if one of the modules does not contain module-info.java
diff --git a/src/it/projects/MJAVADOC-555_aggr_mixed/invoker.properties b/src/it/projects/MJAVADOC-555_aggr_mixed/invoker.properties
new file mode 100644
index 0000000..768d035
--- /dev/null
+++ b/src/it/projects/MJAVADOC-555_aggr_mixed/invoker.properties
@@ -0,0 +1,19 @@
+# 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 javadoc:aggregate
\ No newline at end of file
diff --git a/src/it/projects/MJAVADOC-555_aggr_mixed/module1/pom.xml b/src/it/projects/MJAVADOC-555_aggr_mixed/module1/pom.xml
new file mode 100644
index 0000000..288012b
--- /dev/null
+++ b/src/it/projects/MJAVADOC-555_aggr_mixed/module1/pom.xml
@@ -0,0 +1,32 @@
+<?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>
+		<artifactId>javadoc-maven-report-exception</artifactId>
+		<groupId>testcase</groupId>
+		<version>1.0-SNAPSHOT</version>
+	</parent>
+	<artifactId>module1</artifactId>
+</project>
\ No newline at end of file
diff --git a/src/it/projects/MJAVADOC-555_aggr_mixed/module1/src/main/java/module-info.java b/src/it/projects/MJAVADOC-555_aggr_mixed/module1/src/main/java/module-info.java
new file mode 100644
index 0000000..0dd7ad2
--- /dev/null
+++ b/src/it/projects/MJAVADOC-555_aggr_mixed/module1/src/main/java/module-info.java
@@ -0,0 +1,23 @@
+/*
+ * 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.
+ */
+
+module module1
+{
+	exports module1;
+}
\ No newline at end of file
diff --git a/src/it/projects/MJAVADOC-555_aggr_mixed/module1/src/main/java/module1/Main.java b/src/it/projects/MJAVADOC-555_aggr_mixed/module1/src/main/java/module1/Main.java
new file mode 100644
index 0000000..e60dbdb
--- /dev/null
+++ b/src/it/projects/MJAVADOC-555_aggr_mixed/module1/src/main/java/module1/Main.java
@@ -0,0 +1,24 @@
+package module1;
+
+/*
+ * 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.
+ */
+
+public final class Main
+{
+}
diff --git a/src/it/projects/MJAVADOC-555_aggr_mixed/module2/pom.xml b/src/it/projects/MJAVADOC-555_aggr_mixed/module2/pom.xml
new file mode 100644
index 0000000..bc44c23
--- /dev/null
+++ b/src/it/projects/MJAVADOC-555_aggr_mixed/module2/pom.xml
@@ -0,0 +1,52 @@
+<?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>
+    <artifactId>javadoc-maven-report-exception</artifactId>
+    <groupId>testcase</groupId>
+    <version>1.0-SNAPSHOT</version>
+  </parent>
+  <artifactId>module2</artifactId>
+  
+  <build>
+    <pluginManagement>
+      <plugins>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-jar-plugin</artifactId>
+          <version>2.3.2</version>
+          <configuration>
+            <archive>
+              <manifestEntries>
+                <Automatic-Module-Name>module2</Automatic-Module-Name>
+              </manifestEntries>
+            </archive>
+          </configuration>
+        </plugin>
+      </plugins>
+    </pluginManagement>
+  </build>
+
+</project>
\ No newline at end of file
diff --git a/src/it/projects/MJAVADOC-555_aggr_mixed/module2/src/main/java/module2/Main.java b/src/it/projects/MJAVADOC-555_aggr_mixed/module2/src/main/java/module2/Main.java
new file mode 100644
index 0000000..b864f0e
--- /dev/null
+++ b/src/it/projects/MJAVADOC-555_aggr_mixed/module2/src/main/java/module2/Main.java
@@ -0,0 +1,24 @@
+package module2;
+
+/*
+ * 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.
+ */
+
+public final class Main
+{
+}
diff --git a/src/it/projects/MJAVADOC-555_aggr_mixed/pom.xml b/src/it/projects/MJAVADOC-555_aggr_mixed/pom.xml
new file mode 100644
index 0000000..c881914
--- /dev/null
+++ b/src/it/projects/MJAVADOC-555_aggr_mixed/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>
+
+  <artifactId>javadoc-maven-report-exception</artifactId>
+  <groupId>testcase</groupId>
+  <version>1.0-SNAPSHOT</version>
+  <packaging>pom</packaging>
+  
+  <url>https://issues.apache.org/jira/browse/MJAVADOC-555</url>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+
+  <build>
+    <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-javadoc-plugin</artifactId>
+        <version>@project.version@</version>
+        <executions>
+          <execution>
+            <id>aggregate</id>
+            <goals>
+              <goal>aggregate</goal>
+            </goals>
+            <phase>site</phase>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+  <modules>
+    <module>module1</module>
+    <module>module2</module>
+  </modules>
+
+</project>
\ No newline at end of file
diff --git a/src/it/projects/MJAVADOC-555_aggr_mixed/verify.groovy b/src/it/projects/MJAVADOC-555_aggr_mixed/verify.groovy
new file mode 100644
index 0000000..e75b96c
--- /dev/null
+++ b/src/it/projects/MJAVADOC-555_aggr_mixed/verify.groovy
@@ -0,0 +1,38 @@
+/*
+ * 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.
+ */
+ 
+int javaVersion = System.getProperty( "java.specification.version" ) as Integer
+if ( javaVersion >= 11 ) {
+    def index = new File( basedir, 'target/site/apidocs/index.html')
+
+	assert index.text =~ /<a href="module1\/module-summary\.html">module1<\/a>/
+	assert index.text =~ /<a href="module2\/module-summary\.html">module2<\/a>/
+	
+	assert new File( basedir, 'target/site/apidocs/module1/module-summary.html').exists()
+	assert new File( basedir, 'target/site/apidocs/module2/module-summary.html').exists()
+} 
+else {
+    def overview = new File( basedir, 'target/site/apidocs/overview-summary.html')
+
+	assert overview.text =~ /<a href="module1-summary.html">module1<\/a>/
+	assert overview.text =~ /<a href="module2-summary.html">module2<\/a>/
+	
+	assert new File( basedir, 'target/site/apidocs/module1-summary.html').exists()
+	assert new File( basedir, 'target/site/apidocs/module2-summary.html').exists()
+} 
diff --git a/src/it/projects/MJAVADOC-555_link-automatic-modules/invoker.properties b/src/it/projects/MJAVADOC-555_link-automatic-modules/invoker.properties
new file mode 100644
index 0000000..d47ff2a
--- /dev/null
+++ b/src/it/projects/MJAVADOC-555_link-automatic-modules/invoker.properties
@@ -0,0 +1,19 @@
+# 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-555_link-automatic-modules/pom.xml b/src/it/projects/MJAVADOC-555_link-automatic-modules/pom.xml
new file mode 100644
index 0000000..6c5522c
--- /dev/null
+++ b/src/it/projects/MJAVADOC-555_link-automatic-modules/pom.xml
@@ -0,0 +1,75 @@
+<?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>testcase</groupId>
+  <artifactId>javadoc-cannot-link-to-automatic-modules</artifactId>
+  <version>1.0-SNAPSHOT</version>
+
+  <url>https://issues.apache.org/jira/browse/MJAVADOC-555</url>
+  
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    <guava.version>27.0.1-jre</guava.version>
+  </properties>
+
+  <build>
+    <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-javadoc-plugin</artifactId>
+        <version>@project.version@</version>
+        <executions>
+          <execution>
+            <id>attach-javadocs</id>
+            <goals>
+              <goal>jar</goal>
+            </goals>
+            <configuration>
+              <links>
+                <link>https://google.github.io/guava/releases/${guava.version}/api/docs/</link>
+              </links>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+  <dependencies>
+    <dependency>
+      <groupId>com.google.guava</groupId>
+      <artifactId>guava</artifactId>
+      <version>${guava.version}</version>
+    </dependency>
+  </dependencies>
+</project>
\ No newline at end of file
diff --git a/src/it/projects/MJAVADOC-555_link-automatic-modules/src/main/java/com/testcase/Testcase.java b/src/it/projects/MJAVADOC-555_link-automatic-modules/src/main/java/com/testcase/Testcase.java
new file mode 100644
index 0000000..0dedddd
--- /dev/null
+++ b/src/it/projects/MJAVADOC-555_link-automatic-modules/src/main/java/com/testcase/Testcase.java
@@ -0,0 +1,30 @@
+package com.testcase;
+
+/*
+ * 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.
+ */
+
+import com.google.common.collect.Multimap;
+
+public class Testcase
+{
+	public Multimap<String, String> test()
+	{
+		return null;
+	}
+}
diff --git a/src/it/projects/MJAVADOC-555_link-automatic-modules/src/main/java/module-info.java b/src/it/projects/MJAVADOC-555_link-automatic-modules/src/main/java/module-info.java
new file mode 100644
index 0000000..05a60d9
--- /dev/null
+++ b/src/it/projects/MJAVADOC-555_link-automatic-modules/src/main/java/module-info.java
@@ -0,0 +1,22 @@
+/*
+ * 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.
+ */
+module jul_to_slf4j
+{
+	requires com.google.common;
+}
\ No newline at end of file
diff --git a/src/it/projects/MJAVADOC-555_link-automatic-modules/verify.groovy b/src/it/projects/MJAVADOC-555_link-automatic-modules/verify.groovy
new file mode 100644
index 0000000..df3df50
--- /dev/null
+++ b/src/it/projects/MJAVADOC-555_link-automatic-modules/verify.groovy
@@ -0,0 +1,33 @@
+/*
+ * 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.
+ */
+
+def classFile 
+int javaVersion = System.getProperty( "java.specification.version" ) as Integer
+if ( javaVersion >= 11 ) {
+ classFile = new File( basedir, 'target/apidocs/jul_to_slf4j/com/testcase/Testcase.html')
+} else {
+ classFile = new File( basedir, 'target/apidocs/com/testcase/Testcase.html')
+}
+
+def p = /<a href="([^"]+)"(?:[^>]+)>Multimap<\/a>/
+
+def m = classFile.text =~ p
+
+assert m.hasGroup()
+assert m[0][1] == "https://google.github.io/guava/releases/27.0.1-jre/api/docs/com/google/common/collect/Multimap.html?is-external=true" 
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 a068b74..e6cea07 100644
--- a/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
+++ b/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
@@ -84,6 +84,7 @@
 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.ResolvePathRequest;

 import org.codehaus.plexus.languages.java.jpms.ResolvePathsRequest;

 import org.codehaus.plexus.languages.java.jpms.ResolvePathsResult;

 import org.codehaus.plexus.languages.java.version.JavaVersion;

@@ -1822,6 +1823,15 @@
 

         return Collections.singletonList( new File( p.getBuild().getOutputDirectory() ) );

     }

+    

+    protected File getArtifactFile( MavenProject project )

+    {

+        if ( project.getArtifact() != null )

+        {

+            return project.getArtifact().getFile();

+        }

+        return null;

+    }

 

     /**

      * @param p not null maven project

@@ -2025,7 +2035,6 @@
         {

             packageNames = getPackageNames( files );

         }

-        List<String> filesWithUnnamedPackages = getFilesWithUnnamedPackages( files );

 

         // ----------------------------------------------------------------------

         // Javadoc output directory as File

@@ -2128,9 +2137,11 @@
             // Write argfile file and include it in the command line

             // ----------------------------------------------------------------------

 

-            if ( !filesWithUnnamedPackages.isEmpty() )

+            List<String> specialFiles = getSpecialFiles( files );

+

+            if ( !specialFiles.isEmpty() )

             {

-                addCommandLineArgFile( cmd, javadocOutputDirectory, filesWithUnnamedPackages );

+                addCommandLineArgFile( cmd, javadocOutputDirectory, specialFiles );

             }

         }

         else

@@ -2689,7 +2700,15 @@
             {

                 if ( subProject != project )

                 {

-                    classpathElements.addAll( getProjectBuildOutputDirs( subProject ) );

+                    File projectArtifactFile = getArtifactFile( subProject );

+                    if ( projectArtifactFile != null )

+                    {

+                        classpathElements.add( projectArtifactFile );

+                    }

+                    else

+                    {

+                        classpathElements.addAll( getProjectBuildOutputDirs( subProject ) );

+                    }

 

                     try

                     {

@@ -4515,6 +4534,70 @@
         

         return returnList;

     }

+    

+    /**

+     * Either return only the module descriptor or all sourcefiles per sourcepath

+     * @param sourcePaths could be null

+     * @param files       not null

+     * @return a list of files

+     */

+    private List<String> getSpecialFiles( Map<Path, Collection<String>> sourcePaths )

+    {

+        if ( !StringUtils.isEmpty( sourcepath ) )

+        {

+            return new ArrayList<>();

+        }

+        

+        boolean containsModuleDescriptor = false;

+        for ( Collection<String> sourcepathFiles : sourcePaths.values() )

+        {

+            containsModuleDescriptor = sourcepathFiles.contains( "module-info.java" );

+            if ( containsModuleDescriptor )

+            {

+                break;

+            }

+        }

+        

+        if ( containsModuleDescriptor )

+        {

+            return getModuleSourcePathFiles( sourcePaths );

+        }

+        else

+        {

+            return getFilesWithUnnamedPackages( sourcePaths );

+        }

+    }

+

+    private List<String> getModuleSourcePathFiles( Map<Path, Collection<String>> sourcePaths )

+    {

+        List<String> returnList = new ArrayList<>();

+        

+        for ( Entry<Path, Collection<String>> currentPathEntry : sourcePaths.entrySet() )

+        {

+            Path currentSourcePath = currentPathEntry.getKey();

+            if ( currentPathEntry.getValue().contains( "module-info.java" ) )

+            {

+                returnList.add( currentSourcePath.resolve( "module-info.java" ).toAbsolutePath().toString() );

+            }

+            else

+            {

+                for ( String currentFile : currentPathEntry.getValue() )

+                {

+                    /*

+                     * Remove the miscellaneous files

+                     * http://docs.oracle.com/javase/1.4.2/docs/tooldocs/solaris/javadoc.html#unprocessed

+                     */

+                    if ( currentFile.contains( "doc-files" ) )

+                    {

+                        continue;

+                    }

+            

+                    returnList.add( currentSourcePath.resolve( currentFile ).toAbsolutePath().toString() );

+                }

+            }

+        }

+        return returnList;

+    }

 

     /**

      * Generate an <code>options</code> file for all options and arguments and add the <code>@options</code> in the

@@ -4822,37 +4905,86 @@
             addArgIf( arguments, breakiterator, "-breakiterator", SINCE_JAVADOC_1_5 );

         }

         

-        Collection<String> reactorKeys = new HashSet<>( session.getProjects().size() );

+        Map<String, MavenProject> reactorKeys = new HashMap<>( session.getProjects().size() );

         for ( MavenProject reactorProject : session.getProjects() )

         {

-            reactorKeys.add( ArtifactUtils.versionlessKey( reactorProject.getGroupId(),

-                                                           reactorProject.getArtifactId() ) );

+            reactorKeys.put( ArtifactUtils.versionlessKey( reactorProject.getGroupId(),

+                                                           reactorProject.getArtifactId() ), reactorProject );

         }

         

         final LocationManager locationManager = new LocationManager();

         

         Collection<String> additionalModules = new ArrayList<>();

         

+        boolean containsModuleDescriptor = false;

+        for ( Collection<Path> sourcepaths : allSourcePaths.values() )

+        {

+            if ( findMainDescriptor( sourcepaths ) != null )

+            {

+                containsModuleDescriptor = true;

+            }

+        }

+        

+        

         Path moduleSourceDir = null;

-        if ( allSourcePaths.size() > 1 )

+        if ( containsModuleDescriptor && allSourcePaths.size() > 1 )

         {

             for ( Map.Entry<String, Collection<Path>> projectSourcepaths : allSourcePaths.entrySet() )

             {

-                if ( reactorKeys.contains( projectSourcepaths.getKey() ) )

+                MavenProject aggregatorProject = reactorKeys.get( projectSourcepaths.getKey() );

+                if ( aggregatorProject != null )

                 {

-                    File moduleDescriptor = findMainDescriptor( projectSourcepaths.getValue() );

-                    if ( moduleDescriptor != null )

+                    String moduleName = null;

+                    

+                    // Prefer jar over outputDirectory, since it may may contain an automatic module name

+                    File artifactFile = getArtifactFile( aggregatorProject );

+                    if ( artifactFile != null ) 

+                    {

+                        ResolvePathRequest<File> request = ResolvePathRequest.ofFile( artifactFile );

+                        try

+                        {

+                            moduleName = locationManager.resolvePath( request ).getModuleDescriptor().name();

+                        }

+                        catch ( RuntimeException e )

+                        {

+                            // most likely an invalid module name based on filename

+                            if ( !"java.lang.module.FindException".equals( e.getClass().getName() ) )

+                            {

+                                throw e;

+                            }

+                        }

+                        catch ( IOException e )

+                        {

+                            throw new MavenReportException( e.getMessage(), e );

+                        }

+                    }

+                    else

+                    {

+                        File moduleDescriptor = findMainDescriptor( projectSourcepaths.getValue() );

+                        

+                        if ( moduleDescriptor != null )

+                        {

+                            ResolvePathsRequest<File> request =

+                                            ResolvePathsRequest.ofFiles( Collections.<File>emptyList() )

+                                                               .setMainModuleDescriptor( moduleDescriptor );

+

+                            try

+                            {

+                                moduleName =

+                                    locationManager.resolvePaths( request ).getMainModuleDescriptor().name();

+                            }

+                            catch ( IOException e )

+                            {

+                                throw new MavenReportException( e.getMessage(), e );

+                            }

+                        }

+                    }

+                    if ( moduleName != null )

                     {

                         moduleSourceDir = javadocOutputDirectory.toPath().resolve( "src" );

                         try

                         {

                             moduleSourceDir = Files.createDirectories( moduleSourceDir );

-                            ResolvePathsRequest<File> request =

-                                ResolvePathsRequest.withFiles( Collections.<File>emptyList() )

-                                                   .setMainModuleDescriptor( moduleDescriptor );

-                            

-                            String moduleName =

-                                locationManager.resolvePaths( request ).getMainModuleDescriptor().name();

                             

                             additionalModules.add( moduleName );

                             

@@ -4896,7 +5028,7 @@
         if ( javadocRuntimeVersion.isAtLeast( "9" ) && ( isAggregator() || mainDescriptor != null ) && !isTest() )

         {

             ResolvePathsRequest<File> request =

-                ResolvePathsRequest.withFiles( getPathElements() ).setAdditionalModules( additionalModules );

+                ResolvePathsRequest.ofFiles( getPathElements() ).setAdditionalModules( additionalModules );

             

             if ( mainDescriptor != null )

             {