From 58545123bc46374c0d2db933b7f1e03713ca37e9 Mon Sep 17 00:00:00 2001 From: Nicola Corti Date: Fri, 30 Oct 2026 15:38:11 -0400 Subject: [PATCH] Add Java formatting tasks and CI check --- .github/workflows/build.yml | 14 ++++++++++++++ README.md | 8 ++++++++ build.gradle | 20 ++++++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 980310b..bf7722a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,6 +9,20 @@ permissions: contents: read jobs: + format: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + distribution: zulu + java-version: '17' + - name: Set up Gradle + uses: gradle/actions/setup-gradle@v4 + - name: Check Java formatting + run: ./gradlew formatCheck + build: runs-on: ubuntu-latest steps: diff --git a/README.md b/README.md index dfc3a29..8564bc1 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,14 @@ Run `./gradlew publishToMavenLocal` to publish all three artifacts to your local Maven repository, using the version from the `artifacts/` configuration files. The published class files target Java 7, matching earlier SoLoader releases. +## Formatting Java sources + +From this directory, run `./gradlew format` to format all Java sources, or +`./gradlew formatCheck` to check them without making changes. Both commands work +in a standalone checkout or in `fbsource/fbandroid/libraries/soloader` and use a +pinned Google Java Format version downloaded by Gradle. No formatter binary is +stored in the repository. + The existing [Buck](https://buckbuild.com/) build is also available. Once you have Buck installed, run the following commands from the project root directory: ```shell diff --git a/build.gradle b/build.gradle index c5d2607..1f146df 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,25 @@ plugins { id 'com.android.library' version '9.2.1' apply false + id 'com.diffplug.spotless' version '8.0.0' +} + +spotless { + java { + target 'java/**/*.java' + googleJavaFormat('1.25.2') + } +} + +tasks.register('format') { + group = 'formatting' + description = 'Format all SoLoader Java sources.' + dependsOn 'spotlessApply' +} + +tasks.register('formatCheck') { + group = 'verification' + description = 'Check formatting of all SoLoader Java sources.' + dependsOn 'spotlessCheck' } def artifactVersions = ['ANNOTATION', 'NATIVELOADER', 'SOLOADER'].collect { artifact ->