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

slachiewicz 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 a2ac4f47 Gate --add-stylesheet on the javadoc tool version
a2ac4f47 is described below

commit a2ac4f4799773b25454b19a968b2e4cbafc93e10
Author: Sylwester Lachiewicz <[email protected]>
AuthorDate: Wed Nov 4 16:58:08 2026 +0000

    Gate --add-stylesheet on the javadoc tool version
    
    The check compared the JVM running Maven with 10, so Maven on Java 8 with a 
newer javadoc toolchain dropped the additional stylesheets. Fixes #1434
---
 .../maven/plugins/javadoc/AbstractJavadocMojo.java      | 13 ++++++++-----
 .../apache/maven/plugins/javadoc/JavadocReportTest.java | 17 +++++++++++++++++
 2 files changed, 25 insertions(+), 5 deletions(-)

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 2a6b144f..4a53ea84 100644
--- a/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
+++ b/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
@@ -2756,11 +2756,14 @@ public abstract class AbstractJavadocMojo extends 
AbstractMojo {
             Optional<File> styleSheet = 
getAddStylesheet(getJavadocDirectory(), addStylesheet);
 
             if (styleSheet.isPresent()) {
-                addArgIfNotEmpty(
-                        arguments,
-                        "--add-stylesheet",
-                        
JavadocUtil.quotedPathArgument(styleSheet.get().getAbsolutePath()),
-                        JavaVersion.parse("10"));
+                if (javadocRuntimeVersion.isAtLeast("10")) {
+                    addArgIfNotEmpty(
+                            arguments,
+                            "--add-stylesheet",
+                            
JavadocUtil.quotedPathArgument(styleSheet.get().getAbsolutePath()));
+                } else if (getLog().isWarnEnabled()) {
+                    getLog().warn("--add-stylesheet option is not supported on 
javadoc version < 10");
+                }
             }
         }
     }
diff --git 
a/src/test/java/org/apache/maven/plugins/javadoc/JavadocReportTest.java 
b/src/test/java/org/apache/maven/plugins/javadoc/JavadocReportTest.java
index 3bd7d2e9..b165feea 100644
--- a/src/test/java/org/apache/maven/plugins/javadoc/JavadocReportTest.java
+++ b/src/test/java/org/apache/maven/plugins/javadoc/JavadocReportTest.java
@@ -1442,6 +1442,23 @@ class JavadocReportTest {
         }
     }
 
+    /**
+     * <code>--add-stylesheet</code> follows the javadoc tool version, not the 
JVM running Maven.
+     *
+     * @throws Exception if any
+     */
+    @InjectMojo(goal = "javadoc", pom = 
"addstylesheets-test-plugin-config.xml")
+    @Basedir("/unit/addstylesheets-test")
+    @Test
+    void testAddStylesheetsOnJavadoc9(JavadocReport mojo) throws Exception {
+        deleteDirectory(new File(getBasedir(), "target"));
+        setVariableValueToObject(mojo, "javadocVersion", "9");
+        mojo.execute();
+
+        Path apidocs = new File(getBasedir(), "/target/site/apidocs").toPath();
+        
assertThat(readFile(apidocs.resolve("options"))).doesNotContain("--add-stylesheet");
+    }
+
     /**
      * <code>sourcepath</code> accepts the path separator of the other 
platform (MJAVADOC-262).
      *

Reply via email to