Skip to content

Support markdown javadoc #2467

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
manger opened this issue Apr 18, 2025 · 2 comments
Open

Support markdown javadoc #2467

manger opened this issue Apr 18, 2025 · 2 comments

Comments

@manger
Copy link

manger commented Apr 18, 2025

Java 23+ supports markdown for javadoc, as per JEP 467: Markdown Documentation Comments. Spotless breaks the markdown javadoc when it tries to reformat it.

Consider a class with javadoc that has a long hyperlink. Spotless wants to move the link to a new line to
limit the line length, but fails to keep the /// prefix needed for markdown javadoc.

/// Hello, World!
///
/// See [JEP_467:_Markdown_Documentation_Comments](https://openjdk.org/jeps/467#abcdefghijklmnopqrstuvwxyz)
public class Hello {}

After applying Spotless:

/// Hello, World!
///
/// See
// [JEP_467:_Markdown_Documentation_Comments](https://openjdk.org/jeps/467#abcdefghijklmnopqrstuvwxyz)
public class Hello {}

The link no longer appears in the javadoc.

@jbduncan
Copy link
Member

@manger Welcome!

The choice of formatters will most likely have an impact on where the cause of this issue lies. Can you share an minimal, reproducible example with us?

@manger
Copy link
Author

manger commented Apr 20, 2025

Minimal reproducible example:

Java code is as in the issue: src/main/java/Hello.java

/// Hello, World!
///
/// See [JEP_467:_Markdown_Documentation_Comments](https://openjdk.org/jeps/467#abcdefghijklmnopqrstuvwxyz)
public class Hello {}

Gradle Kotlin build file: build.gradle.kts

plugins {
  java
  id("com.diffplug.spotless") version "7.0.3"
}

repositories {
  mavenCentral()
}

java {
  toolchain {
    languageVersion = JavaLanguageVersion.of(23)
  }
}

spotless {
  java {
    googleJavaFormat()
  }
}

Tools:

  • Java: openjdk version "23.0.1" 2024-10-15
  • Gradle: Gradle 8.13 (Kotlin: 2.0.21, Groovy: 3.0.22, OS: Mac OS X 15.4 aarch64)

Javadoc (gradle javadoc) correctly includes the link iff Spotless has not been applied: build/docs/javadoc/Hello.html

<p>Hello, World!</p>
<p>See <a href="https://openjdk.org/jeps/467#abcdefghijklmnopqrstuvwxyz">JEP_467:_Markdown_Documentation_Comments</a></p>

After applying Spotless (gradle spotlessApply) the link is wrapped onto a new line without keeping the /// prefix required for markdown: src/main/java/Hello.java

/// Hello, World!
///
/// See
// [JEP_467:_Markdown_Documentation_Comments](https://openjdk.org/jeps/467#abcdefghijklmnopqrstuvwxyz)
public class Hello {}

Javadoc (gradle javadoc) is now missing the link: build/docs/javadoc/Hello.html

<p>Hello, World!</p>
<p>See</p>

Presumably googleJavaFormat needs to keep the /// prefix when wrapping long comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants