diffplug / diffplug/spotless

spotless-maven-plugin: <toggleOffOn/> breaks <forbidWildcardImports/>

オープン
#2,859 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Java
スター
5.6k
フォーク
559
平均マージ
1日 14時間
マージ済み PR(30日)
43

説明

It seems as though adding ` somehow interferes with ``

Consider the following minimal configuration:
```xml



com.diffplug.spotless
spotless-maven-plugin
3.1.0










```

And the following source code:
```java
package org.example;

import java.util.*;
import java.sql.PreparedStatement;

public class ImportMess {
}
```

With this configuration, running `mvn spotless:check` will fail on the ``:
```
➜ demo mvn spotless:check
WARNING: A terminally deprecated method in sun.misc.Unsafe has been called
WARNING: sun.misc.Unsafe::staticFieldBase has been called by com.google.inject.internal.aop.HiddenClassDefiner (file:/opt/homebrew/Cellar/maven/3.9.11/libexec/lib/guice-5.1.0-classes.jar)
WARNING: Please consider reporting this to the maintainers of class com.google.inject.internal.aop.HiddenClassDefiner
WARNING: sun.misc.Unsafe::staticFieldBase will be removed in a future release
[INFO] Scanning for projects...
[INFO]
[INFO] ----------------------< org.example:spotlessdemo >----------------------
[INFO] Building spotlessdemo 1.0-SNAPSHOT
[INFO] from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- spotless:3.1.0:check (default-cli) @ spotlessdemo ---
[INFO] Index file corresponds to a different configuration of the plugin. Either the plugin version or its configuration has changed. Fallback to an empty index
[INFO] Spotless.Java is keeping 1 files clean - 1 needs changes to be clean, 0 were already clean, 0 were skipped because caching determined they were already clean
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.486 s
[INFO] Finished at: 2026-02-22T21:13:20+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.diffplug.spotless:spotless-maven-plugin:3.1.0:check (default-cli) on project spotlessdemo: The following files had format violations:
[ERROR] src/test/java/org/example/ImportMess.java
[ERROR] @@ -1,7 +1,6 @@
[ERROR] package·org.example;
[ERROR]
[ERROR] import·java.util.*;
[ERROR] -import·java.sql.PreparedStatement;
[ERROR]
[ERROR] public·class·ImportMess·{
[ERROR] }
[ERROR] Run 'mvn spotless:apply' to fix these violations.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
```

But if you remove ``, it will now fail on the ``:
```
➜ demo mvn spotless:check
WARNING: A terminally deprecated method in sun.misc.Unsafe has been called
WARNING: sun.misc.Unsafe::staticFieldBase has been called by com.google.inject.internal.aop.HiddenClassDefiner (file:/opt/homebrew/Cellar/maven/3.9.11/libexec/lib/guice-5.1.0-classes.jar)
WARNING: Please consider reporting this to the maintainers of class com.google.inject.internal.aop.HiddenClassDefiner
WARNING: sun.misc.Unsafe::staticFieldBase will be removed in a future release
[INFO] Scanning for projects...
[INFO]
[INFO] ----------------------< org.example:spotlessdemo >----------------------
[INFO] Building spotlessdemo 1.0-SNAPSHOT
[INFO] from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- spotless:3.1.0:check (default-cli) @ spotlessdemo ---
[INFO] Index file corresponds to a different configuration of the plugin. Either the plugin version or its configuration has changed. Fallback to an empty index
[INFO] Spotless.Java is keeping 1 files clean - 1 needs changes to be clean, 0 were already clean, 0 were skipped because caching determined they were already clean
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.398 s
[INFO] Finished at: 2026-02-22T21:14:20+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.diffplug.spotless:spotless-maven-plugin:3.1.0:check (default-cli) on project spotlessdemo: Unable to format file /Users/allon/Downloads/demo/src/test/java/org/example/ImportMess.java
[ERROR] Step 'forbidWildcardImports' found problem in 'ImportMess.java':
[ERROR] ImportMess.java:L3 forbidWildcardImports(import java.util.*;) Do not use wildcard imports (e.g. java.util.*) - replace with specific class imports (e.g. java.util.List) as 'spotlessApply' cannot auto-fix this
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
```

**Note:**
The `` isn't really important here, I added it just to demonstrate that the project structure is correct and spotless is actually picking up _something_ from that file.

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

最小限の pom.xml 構成と src/test/java/org/example/ImportMess.java を使い、mvn spotless:check で問題を再現します。まず がある場合とない場合の動作を比較します。toggleOffOn、removeUnusedImports、forbidWildcardImports の Java フォーマット手順を追跡します。両方のチェックが、どちらか一方がもう一方を抑制または置き換えることなく、想定される違反を報告すれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
java
領域
build-system
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
48/100

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

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