This is an automated email from the ASF dual-hosted git repository.
elharo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-javadoc-plugin.git
The following commit(s) were added to refs/heads/master by this push:
new 1c336b18 [MJAVADOC-736] Detect module-info.java from source when
outputDirectory is missing (#1455)
1c336b18 is described below
commit 1c336b1830052b89813ec1711913de2739e89eed
Author: Arturo Bernal <[email protected]>
AuthorDate: Fri Nov 27 14:33:13 2026 +0100
[MJAVADOC-736] Detect module-info.java from source when outputDirectory is
missing (#1455)
getClassesFile returns the configured outputDirectory even when it does not
exist on disk yet, e.g. when the javadoc goal runs directly without a prior
compile. The module-descriptor resolution loop treated that non-null but absent
path as authoritative and never tried the source-based fallback, so a project
with a real module-info.java got misclassified as unnamed and the whole report
failed.
Also populate the synthetic module-source-path stub with the real
module-info.java when falling back to source, since otherwise javadoc cannot
discover the module by name even though patch-module supplies its real sources.
Claude-Session: https://claude.ai/code/session_0153qygyTP2LcbRbWVPHCmjg
---
.../invoker.properties | 19 ++++++++
.../MJAVADOC-736_clean-before-javadoc/pom.xml | 50 ++++++++++++++++++++++
.../src/main/java/module-info.java | 23 ++++++++++
.../plugins/javadoc/it/mjavadoc736/HelloWorld.java | 27 ++++++++++++
.../verify.groovy | 29 +++++++++++++
.../maven/plugins/javadoc/AbstractJavadocMojo.java | 25 ++++++++---
6 files changed, 168 insertions(+), 5 deletions(-)
diff --git
a/src/it/projects/MJAVADOC-736_clean-before-javadoc/invoker.properties
b/src/it/projects/MJAVADOC-736_clean-before-javadoc/invoker.properties
new file mode 100644
index 00000000..191ef04e
--- /dev/null
+++ b/src/it/projects/MJAVADOC-736_clean-before-javadoc/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 = javadoc:javadoc
diff --git a/src/it/projects/MJAVADOC-736_clean-before-javadoc/pom.xml
b/src/it/projects/MJAVADOC-736_clean-before-javadoc/pom.xml
new file mode 100644
index 00000000..9a23f8e1
--- /dev/null
+++ b/src/it/projects/MJAVADOC-736_clean-before-javadoc/pom.xml
@@ -0,0 +1,50 @@
+<?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/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.maven.plugins.javadoc.it</groupId>
+ <artifactId>mjavadoc736</artifactId>
+ <version>1.0-SNAPSHOT</version>
+
+ <url>https://issues.apache.org/jira/browse/MJAVADOC-736</url>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <version>@project.version@</version>
+ <configuration>
+ <release>9</release>
+ <detectJavaApiLink>false</detectJavaApiLink>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git
a/src/it/projects/MJAVADOC-736_clean-before-javadoc/src/main/java/module-info.java
b/src/it/projects/MJAVADOC-736_clean-before-javadoc/src/main/java/module-info.java
new file mode 100644
index 00000000..5937a5a0
--- /dev/null
+++
b/src/it/projects/MJAVADOC-736_clean-before-javadoc/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.
+ */
+
+/** Exports a single package for MJAVADOC-736 IT. */
+module mjavadoc736 {
+ exports org.apache.maven.plugins.javadoc.it.mjavadoc736;
+}
diff --git
a/src/it/projects/MJAVADOC-736_clean-before-javadoc/src/main/java/org/apache/maven/plugins/javadoc/it/mjavadoc736/HelloWorld.java
b/src/it/projects/MJAVADOC-736_clean-before-javadoc/src/main/java/org/apache/maven/plugins/javadoc/it/mjavadoc736/HelloWorld.java
new file mode 100644
index 00000000..597755ad
--- /dev/null
+++
b/src/it/projects/MJAVADOC-736_clean-before-javadoc/src/main/java/org/apache/maven/plugins/javadoc/it/mjavadoc736/HelloWorld.java
@@ -0,0 +1,27 @@
+/*
+ * 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.
+ */
+package org.apache.maven.plugins.javadoc.it.mjavadoc736;
+
+/** Says hello. */
+public class HelloWorld {
+ /** Prints a greeting. */
+ public void greet() {
+ System.out.println("hello");
+ }
+}
diff --git a/src/it/projects/MJAVADOC-736_clean-before-javadoc/verify.groovy
b/src/it/projects/MJAVADOC-736_clean-before-javadoc/verify.groovy
new file mode 100644
index 00000000..291cb913
--- /dev/null
+++ b/src/it/projects/MJAVADOC-736_clean-before-javadoc/verify.groovy
@@ -0,0 +1,29 @@
+/*
+ * 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.
+ */
+
+// MJAVADOC-736: javadoc:javadoc must detect the module-info.java in source
even when
+// target/classes doesn't exist yet, e.g. because this goal was run directly
without a
+// prior compile.
+def moduleSummary = new File(basedir,
'target/reports/apidocs/mjavadoc736/module-summary.html')
+assert moduleSummary.exists()
+
+def classFile = new File(basedir,
+
'target/reports/apidocs/mjavadoc736/org/apache/maven/plugins/javadoc/it/mjavadoc736/HelloWorld.html')
+assert classFile.exists()
+assert classFile.text =~ /greet/
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 696c0685..07bc099f 100644
--- a/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
+++ b/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
@@ -4320,10 +4320,11 @@ public abstract class AbstractJavadocMojo extends
AbstractMojo {
MavenProject aggregatedProject =
reactorKeys.get(javadocModule.getGav());
if (aggregatedProject != null &&
!"pom".equals(aggregatedProject.getPackaging())) {
ResolvePathResult result = null;
+ Path moduleDescriptorSource = null;
// Prefer jar over outputDirectory, since it may contain
an automatic module name
File artifactFile = getClassesFile(aggregatedProject);
- if (artifactFile != null) {
+ if (artifactFile != null && artifactFile.exists()) {
ResolvePathRequest<File> request =
ResolvePathRequest.ofFile(artifactFile);
try {
result = locationManager.resolvePath(request);
@@ -4336,12 +4337,16 @@ public abstract class AbstractJavadocMojo extends
AbstractMojo {
} catch (IOException e) {
throw new MavenReportException(e.getMessage(), e);
}
- } else {
- Path moduleDescriptor =
findMainDescriptor(javadocModule.getSourcePaths());
+ }
+
+ // Fall back to the module-info.java source file, e.g.
when outputDirectory
+ // doesn't exist yet because a clean ran after this
project's build started
+ if (result == null || result.getModuleDescriptor() ==
null) {
+ moduleDescriptorSource =
findMainDescriptor(javadocModule.getSourcePaths());
- if (moduleDescriptor != null) {
+ if (moduleDescriptorSource != null) {
try {
- result =
locationManager.parseModuleDescriptor(moduleDescriptor);
+ result =
locationManager.parseModuleDescriptor(moduleDescriptorSource);
} catch (IOException e) {
throw new MavenReportException(e.getMessage(),
e);
}
@@ -4362,6 +4367,16 @@ public abstract class AbstractJavadocMojo extends
AbstractMojo {
if (!Files.isDirectory(modulePath)) {
Files.createDirectory(modulePath);
}
+
+ // No compiled module-info.class to anchor
--module-path on, so the
+ // module-source-path scan needs to see a
module-info.java of its own
+ // here; the rest of the sources are supplied via
--patch-module above.
+ if (moduleDescriptorSource != null) {
+ Path stubDescriptor =
modulePath.resolve("module-info.java");
+ if (!Files.exists(stubDescriptor)) {
+ Files.copy(moduleDescriptorSource,
stubDescriptor);
+ }
+ }
} catch (IOException e) {
throw new MavenReportException(e.getMessage(), e);
}