google-java-format 1.37.0 fails because JavaFormatterOptions.Style is no longer an enum
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 新手友好度
- 74/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 活躍
- 技術堆疊
- java
- 領域
- build-system
研究方向
從 stack trace 中顯示的建構函式所在位置開始檢查 GoogleJavaFormatFormatterFunc.java,接著檢查 GoogleJavaFormatStep.java 和 google-java-format 的版本處理。比較 1.36.1 和 1.37.0 版本中的 API,並找出 Google Java Format 步驟現有的測試。提供的 Gradle 重現案例使用 1.37.0 成功格式化,且相關測試通過後,即表示完成。
由索引模型根據 Issue 內容生成。
描述
Spotless Gradle 8.10.4 fails to initialize google-java-format 1.37.0. The same minimal project formats successfully with 1.36.1.
Environment: Gradle 9.8.2, Temurin JDK 25.0.4.1, Ubuntu 26.04.1 LTS (x86_64).
settings.gradle.kts:
rootProject.name = "formatter-repro"
Complete build.gradle.kts:
plugins { id("com.diffplug.spotless") version "8.10.4" }
repositories { mavenCentral() }
spotless {
java {
target("src/**/*.java")
googleJavaFormat("1.37.0").aosp()
}
}
src/main/java/Sample.java:
class Sample{void run(){System.out.println("sample");}}
Run ./gradlew spotlessApply. Expected: the file is formatted. Actual:
> Task :spotlessJava
> Task :spotlessJavaApply FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':spotlessJavaApply' (registered in build file 'build.gradle.kts').
> There were 1 lint error(s), they must be fixed or suppressed.
src/main/java/Sample.java:LINE_UNDEFINED google-java-format(java.lang.reflect.InvocationTargetException) java.lang.reflect.InvocationTargetException (...)
Resolve these lints or suppress with `suppressLintsFor`
The serialized lint detail contains the underlying exception:
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:74)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:483)
at com.diffplug.spotless.java.GoogleJavaFormatStep$State.createFormat(GoogleJavaFormatStep.java:188)
Caused by: java.lang.NoSuchMethodError: 'com.google.googlejavaformat.java.JavaFormatterOptions$Style com.google.googlejavaformat.java.JavaFormatterOptions$Style.valueOf(java.lang.String)'
at com.diffplug.spotless.glue.java.GoogleJavaFormatFormatterFunc.<init>(GoogleJavaFormatFormatterFunc.java:51)
at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:62)
Upstream cause: google-java-format 1.37.0 changed JavaFormatterOptions.Style from an enum to a record, so Style.valueOf(String) no longer exists. The current Spotless GoogleJavaFormatFormatterFunc still calls it. The enum is present in 1.36.1.
Verified workaround: change only googleJavaFormat("1.37.0") to googleJavaFormat("1.36.1"); spotlessApply then succeeds on the same file and environment.
- 主要語言
- Java
- 星號
- 5.7k
- 分支
- 563
- 平均合併
- 3 天 3 小時
- 30 天內合併 PR
- 14
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
diffplug/spotless 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 1 天內回覆
-
難度 4/5 3-5 天 新手友好度 45/100
維護者通常 1 天內回覆
-
難度 3/5 1-2 天 新手友好度 70/100
維護者通常 1 天內回覆
-
Expose `maxLineLength` on the `googleJavaFormat` step (configurable upstream since gjf 1.37.0)可能已有人在做 @xzxiaoshan 於 8 天前認領。 未關閉
難度 3/5 1-2 天 新手友好度 28/100
維護者通常 1 天內回覆
-
bug
難度 4/5 3-5 天 新手友好度 43/100
diffplug/spotless#3147 · 1 個 reaction ·
維護者通常 1 天內回覆
查看 diffplug/spotless 的全部 Issue
相似的 Issue
-
Documentation
難度 1/5 1 小時以內 新手友好度 88/100
OWASP/SecurityShepherd#1097 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 82/100
Dans-Plugins/Medieval-Roleplay-Engine#392 · 1 則留言 ·
維護者通常 1 天內回覆
-
Invalid If-Modified-Since or If-Unmodified-Since header results in 500 with Request.evaluatePreconditions()可能已有人在做 @pschaub 今天認領。 未關閉kind/bug triage/needs-triage
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆
-
難度 1/5 1 小時以內 新手友好度 70/100
-
難度 2/5 1-3 小時 新手友好度 62/100
Vakore/ZappierGames#236 ·