`removeUnusedImports()` does not parse Markdown Javadoc

未关闭
#3,161 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@1AbdullahButt 已经在做这个了。

开始于 2026年11月6日。

  • #3163 来自 @1AbdullahButt —— 未关闭

评估

难度
4/5
预计耗时
3-5 天
新手友好度
48/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
java

调研方向

Start by tracing the Java removeUnusedImports() implementation and its formatter integration; the issue identifies Gradle classloading and javac's service loader as the suspected path. Reproduce with the provided Java snippet and default settings, then check whether ArrayList and Collection remain imported when referenced only in Markdown Javadoc. Done means those references are preserved during formatting.

由索引模型根据 Issue 内容生成。

描述

  • Java version: 25.0.5.0.3
  • Gradle version: 9.7.1
  • Gradle plugin version: 8.11.0

When using removeUnusedImports() with the default settings, the formatter does not parse Markdown Javadoc comments, meaning classes only referenced within them will be stripped. For example, with the following config:

spotless {
  java {
    removeUnusedImports()
  }
}

This file:

import java.util.ArrayList;
import java.util.Collection;
import java.util.function.Predicate;

/// [ArrayList#add] [Collection#removeIf(Predicate)]
class Test {}

Will be reformatted to:

/// [ArrayList#add] [Collection#removeIf(Predicate)]
class Test {}

Google's formatter uses javac to parse the classes, so this in theory should work. However, Markdown parsing is handled in a separate step — javac uses a service loader to load the class responsible for parsing/transforming markdown.

Due to Gradle's funky classloading, the service loader doesn't find the Markdown parser, and so Markdown doc comments are ignored. I'm not really sure there's a good way to fix this, short of running the formatter in a separate forked process.

主要语言
Java
星标
5.7k
派生
565
平均合并
3 天 7 小时
30 天内合并 PR
13

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

diffplug/spotless 的其他 Issue

查看 diffplug/spotless 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。