Skip to content

style: format Java sources with google-java-format - #266

Merged
epugh merged 2 commits into
apache:mainfrom
adityamparikh:style/chain-one-call-per-line
Oct 26, 2026
Merged

epugh merged 2 commits into
apache:mainfrom
adityamparikh:style/chain-one-call-per-line

Conversation

@adityamparikh

@adityamparikh adityamparikh commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #269 (./gradlew build runs buildSrc's tests): the first commit here is #269, and only the top commit (style: format Java sources with google-java-format) is new.

What

Spotless now formats Java with google-java-format instead of the Eclipse JDT formatter, and the whole codebase is reformatted with it before 1.0.

  • build.gradle.kts: the java block is googleJavaFormat("1.35.0") plus formatAnnotations(). google-java-format sorts imports and removes unused ones itself, so importOrder(), removeUnusedImports(), trimTrailingWhitespace() and endWithNewline() are gone.
  • config/spotless/eclipse-java-formatter.properties is deleted. google-java-format has one fixed style, so there is nothing to configure.
  • .editorconfig gets a [*.java] section that matches the formatter (2-space indent, 4-space continuation, 100 columns), so IDEs indent new code the same way.
  • Everything else is ./gradlew spotlessApply over the Java sources.

Why

One style, applied the same way everywhere, with no formatter settings to tune or review. The Google style also gives the layout the codebase has been missing:

return listCollections().stream()
    .filter(c -> c != null && c.toLowerCase(Locale.ROOT).startsWith(prefix))
    .sorted()
    .limit(MAX_COMPLETION_RESULTS)
    .toList();
public record AliasResult(
    String aliasName,
    @Nullable String collections,
    boolean success,
    String message,
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
        Date timestamp) {}
@McpTool(
    name = "list-collections",
    annotations = @McpTool.McpAnnotations(readOnlyHint = true),
    description = "List solr collections")
  • Chains: once a chain doesn't fit, every call goes on its own line.
  • Arguments: parameters, record components and annotation arguments that don't fit go one per line.
  • Short code: whatever fits on one line, such as @McpComplete(prompt = PromptNames.VIEW_SCHEMA) or record SortClause(String field, String order), stays on one line.

The Eclipse formatter was adopted because google-java-format used to fail on new JDKs with NoSuchMethodError against javac internals. 1.35.0, Spotless 8.9.0's default, runs on JDK 25. It's pinned so a Spotless upgrade can't reformat the codebase by itself. The newest release, 1.37.0, fails on every file under JDK 25, with Spotless 8.9.0 and with 8.10.4.

Verification

  • The change is formatting only. All 130 compiled classes in main and test match the previous output apart from line numbers. This includes instructions, string constants and annotation values (the @McpTool descriptions).
  • Running ./gradlew spotlessApply again changes nothing.
  • ./gradlew build passes, with all 465 tests run and none skipped, plus buildSrc's 12 tests, which run in the same build via build: run buildSrc's tests as part of the build #269.

🤖 Generated with Claude Code

adityamparikh and others added 2 commits October 14, 2026 19:51
Since Gradle 8 the root build asks buildSrc only for the jar on the build
script classpath, so :buildSrc:test never ran and the LICENSE/NOTICE and
RAT exclude tests went unexercised by ./gradlew build, contrary to
AGENTS.md.

Finalize buildSrc's jar with its tests. dependsOn would be a cycle, since
compiling the Kotlin tests needs the jar, and the root build cannot
reference buildSrc's tasks at all.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Signed-off-by: Aditya Parikh <aditya.m.parikh@gmail.com>
Spotless now formats Java with google-java-format instead of the Eclipse
JDT formatter, and the whole codebase is reformatted with it ahead of
1.0. google-java-format has one fixed style, so there is no formatter
configuration to maintain: config/spotless/eclipse-java-formatter.properties
is removed.

In that style a method chain that does not fit on one line has each call
on its own line, and parameters, record components and annotation
arguments that do not fit go one per line. Indentation is 2 spaces with
4 for continuation lines, at 100 columns; .editorconfig gets a [*.java]
section with the same settings so IDEs match.

The Eclipse formatter was chosen earlier because google-java-format
failed on new JDKs with NoSuchMethodError against javac internals.
google-java-format 1.35.0, Spotless 8.9.0's default, runs on JDK 25 and
is pinned so a Spotless upgrade cannot reformat the codebase on its own.
1.37.0, the latest, still fails on JDK 25, with Spotless 8.9.0 and 8.10.4.

The change is formatting only: compiled classes are identical before and
after apart from line numbers, string and annotation constants included.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Signed-off-by: Aditya Parikh <aditya.m.parikh@gmail.com>
@adityamparikh
adityamparikh force-pushed the style/chain-one-call-per-line branch from 9dff2e8 to 04f05bd Compare October 14, 2026 19:51
@sonarqubecloud

Copy link
Copy Markdown

@epugh

epugh commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

better to format now then post 1.0!

@epugh
epugh merged commit 40528b5 into apache:main Oct 26, 2026
2 checks passed
adityamparikh added a commit to adityamparikh/solr-mcp that referenced this pull request Oct 26, 2026
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

Successfully merging this pull request may close these issues.

2 participants