Skip to content

Configure Eclipse WTP XML formatter for Android Studio-like output#128

Closed
Copilot wants to merge 6 commits intomainfrom
copilot/add-java-code-formatter
Closed

Configure Eclipse WTP XML formatter for Android Studio-like output#128
Copilot wants to merge 6 commits intomainfrom
copilot/add-java-code-formatter

Conversation

Copy link
Contributor

Copilot AI commented Mar 9, 2026

The default Eclipse WTP XML formatter was packing multiple short attributes onto the same line (72-char line width), using tabs for indentation, and splitting or combining attributes arbitrarily — producing inconsistent output that diverged from Android Studio's format.

Changes

  • spotless/eclipse-wtp-xml.prefs — new Eclipse WTP formatter config:
    • splitMultiAttrs=true: one attribute per line
    • indentationChar=space + indentationSize=4: 4-space indent (matches Android Studio XML default)
    • lineWidth=160: prevents overly eager line wrapping
  • build.gradle — wire config file into the eclipseWtp('xml') step
  • 378 XML files — reformatted to the new canonical output

Result

<item
    android:title="0/0"
    android:id="@+id/menu_search_counter"
    android:visible="false"
    app:showAsAction="always" />

The formatter is idempotent — re-running spotlessApply on already-formatted files produces no changes.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • dl.google.com
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED --add-opens=java.xml/javax.xml.namespace=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED -Xmx4608m -Dfile.encoding=UTF-8 (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

Add Java Code Formatter with CI Enforcement

This repository has no automated Java code formatter. We want to add one so that:

  1. Code can be formatted automatically by developers with a single command.
  2. Formatting is checked in CI on every PR and push to main.

What to implement

1. build.gradle — Add the Spotless plugin

Add the Spotless Gradle plugin configured to use google-java-format on all *.java source files. The plugin block already has:

plugins {
    id 'com.android.application' version '8.11.1'
    id 'com.google.gms.google-services' version '4.4.1'
}

Add Spotless to it:

id 'com.diffplug.spotless' version '6.25.0'

Then add a spotless configuration block (outside android {}) in build.gradle:

spotless {
    java {
        target 'src/**/*.java'
        googleJavaFormat('1.19.2').aosp()  // AOSP style = 4-space indent, fits Android codebases
        removeUnusedImports()
        trimTrailingWhitespace()
        endWithNewline()
    }
}

2. gradle.properties — JVM args for google-java-format

google-java-format requires extra JVM --add-exports flags when running on JDK 16+ (CI uses JDK 17). Check if gradle.properties already has org.gradle.jvmargs. If it does, append the required flags; if it doesn't, add a new line:

org.gradle.jvmargs=--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \
  --add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \
  --add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED \
  --add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED \
  --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED

3. .github/workflows/check-format.yml — New lightweight CI workflow

Create a new workflow file that runs spotlessCheck on every PR and on pushes to main. It should not compile the native Rust/NDK code (no need for ndk or rust setup) — just check formatting. Use the same Java version (17, temurin) and Gradle caching pattern as the existing preview-apk.yml workflow:

name: Check Java formatting

on:
  push:
    branches: [main]
  pull_request:

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}

jobs:
  spotless:
    name: Check Java formatting (Spotless)
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5
      - uses: actions/setup-java@v5
        with:
          java-version: 17
          distribution: temurin
      - uses: actions/cache@v4
        with:
          path: |
            ~/.gradle/caches
            ~/.gradle/wrapper
          key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
          restore-keys: |
            ${{ runner.os }}-gradle-
      - name: Validate Gradle Wrapper
        uses: gradle/actions/wrapper-validation@v4
      - name: Check formatting
        run: ./gradlew spotlessCheck

4. scripts/format.sh — Developer helper script

Create a small helper script so contributors can format everything locally in one command:

#!/bin/sh
set -e
./gradlew spotlessApply

Make it executable (chmod +x).

5. CONTRIBUTING.md — Document the formatter

In the Coding Conventions section (around line 76), add a note after the existing style guidance explaining:

  • The project uses google-java-format (AOSP style, 4-space indent) enforced via Spotless.
  • Developers can auto-format all files by running scripts/format.sh or ./gradlew spotlessApply.
  • CI will fail if files are not formatted — run the formatter before pushing.

Notes

  • The existing CI workflow (preview-apk.yml) uses actions/checkout@v5, actions/setup-java@v5, actions/cache@v4 — use the same versions for consistency.
  • The spotlessCheck task should be a fast, standalone check with no native compilation required.
  • AOSP style (.aosp()) uses 4-space indentation which is consistent with Android coding conventions and the existing code style seen in the repository.

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: I want to have some code formatter so code can be formatted automatically and code format checked in CI

Assistant: I now have a good picture of the repo. Let me create the PR with a well-tailored setup for Java code formatting.

Assistant: We're waiting for your response to the tool call dialog to continue with creating the pull request.

In the meantime, here's a summary of the plan for adding automated Java formatting to deltachat/deltachat-android:


Plan: Java Code Formatting with google-java-format

The repo is primarily Java (62.8%) with no existing formatter. Here's what will be set up:

1. build.gradle — Spotless plugin

The Spotless Gradle plugin will be added, configured to use **goo...

This pull request was created from Copilot chat.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…cement

Co-authored-by: adbenitez <24558636+adbenitez@users.noreply.github.com>
Copilot AI changed the title [WIP] Add Java code formatter with CI enforcement Add google-java-format via Spotless with CI enforcement Mar 9, 2026
…udio default

Co-authored-by: adbenitez <24558636+adbenitez@users.noreply.github.com>
Copilot AI changed the title Add google-java-format via Spotless with CI enforcement Switch Java formatter from AOSP (4-space) to Google style (2-space) to match Android Studio Mar 10, 2026
…e resolved

Co-authored-by: adbenitez <24558636+adbenitez@users.noreply.github.com>
Copilot AI changed the title Switch Java formatter from AOSP (4-space) to Google style (2-space) to match Android Studio Fix Spotless plugin resolution by adding Gradle Plugin Portal to pluginManagement Mar 10, 2026
Co-authored-by: adbenitez <24558636+adbenitez@users.noreply.github.com>
Copilot AI changed the title Fix Spotless plugin resolution by adding Gradle Plugin Portal to pluginManagement Add XML auto-formatting to Spotless and fix plugin resolution Mar 10, 2026
@adbenitez adbenitez closed this Mar 10, 2026
Copilot stopped work on behalf of adbenitez due to an error March 11, 2026 13:43
@adbenitez adbenitez reopened this Mar 11, 2026
@github-actions
Copy link

To test the changes in this pull request, install this apk:
📦 app-preview.apk

- Add spotless/eclipse-wtp-xml.prefs with Eclipse WTP XML formatter config:
  - splitMultiAttrs=true: each attribute on its own line
  - indentMultipleAttributes=true: proper indentation of split attributes
  - indentationChar=space: use spaces instead of tabs
  - indentationSize=4: 4-space indentation (Android Studio default)
  - lineWidth=160: prevent unnecessary line wrapping
- Update build.gradle to use the new config file
- Apply the new formatter to all 378 XML files in the project

Co-authored-by: adbenitez <24558636+adbenitez@users.noreply.github.com>
Copilot AI changed the title Add XML auto-formatting to Spotless and fix plugin resolution Configure Eclipse WTP XML formatter for Android Studio-like output Mar 11, 2026
Copilot stopped work on behalf of adbenitez due to an error March 11, 2026 14:52
@adbenitez adbenitez closed this Mar 11, 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