`removeUnusedImports()` does not parse Markdown Javadoc

オープン
#3,161 コメント 0 件 リアクション 0 件 担当者 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時間
マージ済み PR(30日)
13

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

diffplug/spotless のほかの issue

diffplug/spotless の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。