Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
83ddd55
feat(client): ensure compat with proguard
stainless-app[bot] Jul 29, 2025
cf6742e
feat: add retryable exception
stainless-app[bot] Jul 29, 2025
27da721
fix(client): r8 support
stainless-app[bot] Jul 31, 2025
9b4d208
chore(internal): reduce proguard ci logging
stainless-app[bot] Jul 31, 2025
0e68dd4
chore(internal): bump ci test timeout
stainless-app[bot] Jul 31, 2025
b42e5bb
codegen metadata
stainless-app[bot] Aug 29, 2025
76d269d
chore(internal): codegen related update
stainless-app[bot] Aug 29, 2025
13fc2ef
feat(api)!: define shared model ConversionRateConfig
stainless-app[bot] Sep 2, 2025
a6e527f
chore: fix formatting
dgellow Sep 2, 2025
e90f837
feat(api): api update
stainless-app[bot] Sep 2, 2025
b290b3a
fix(ci): use java-version 21 for publish step
stainless-app[bot] Sep 3, 2025
3e25650
feat: extract minimum composite to type
stainless-app[bot] Sep 3, 2025
3b2489b
feat(api): api update
stainless-app[bot] Sep 3, 2025
05b6a4e
feat(api): api update
stainless-app[bot] Sep 5, 2025
5d00bf2
feat(api): api update
stainless-app[bot] Sep 10, 2025
185acb8
chore(internal): codegen related update
stainless-app[bot] Sep 11, 2025
247937e
feat(api): api update
stainless-app[bot] Sep 12, 2025
3a4300a
chore(internal): codegen related update
stainless-app[bot] Sep 12, 2025
97bd293
chore(internal): codegen related update
stainless-app[bot] Sep 12, 2025
9bc6ac9
fix(client): incorrect `getPackageVersion` impl
stainless-app[bot] Sep 15, 2025
9c8977c
feat(api): api update
stainless-app[bot] Sep 16, 2025
427df35
feat(client): expose sleeper option
stainless-app[bot] Sep 19, 2025
5d37bc1
chore: improve formatter performance
stainless-app[bot] Sep 19, 2025
cf6fd19
feat(api): api update
stainless-app[bot] Sep 19, 2025
7e80bfe
chore(internal): change some comment formatting
stainless-app[bot] Sep 23, 2025
1764089
fix(client): deserialization of empty objects
stainless-app[bot] Sep 25, 2025
321aa41
feat(api): api update
stainless-app[bot] Sep 29, 2025
b3c5ffa
codegen metadata
stainless-app[bot] Sep 29, 2025
6aa1d53
feat(api): api update
stainless-app[bot] Sep 30, 2025
bf412bc
feat(api): api update
stainless-app[bot] Oct 3, 2025
617892e
feat(api): api update
stainless-app[bot] Oct 3, 2025
0f4e585
feat(api): api update
stainless-app[bot] Oct 6, 2025
ab79480
feat(api): api update
stainless-app[bot] Oct 7, 2025
84cc66c
feat(api): api update
stainless-app[bot] Oct 10, 2025
0c2b180
codegen metadata
stainless-app[bot] Oct 10, 2025
6c895f2
feat(api): api update
stainless-app[bot] Oct 13, 2025
f101f63
feat(api): api update
stainless-app[bot] Oct 15, 2025
a4d2018
codegen metadata
stainless-app[bot] Oct 16, 2025
108cdfc
feat(api): api update
stainless-app[bot] Oct 17, 2025
1a45d5d
feat(api): api update
stainless-app[bot] Oct 23, 2025
e248a04
codegen metadata
stainless-app[bot] Oct 27, 2025
743513b
codegen metadata
stainless-app[bot] Oct 27, 2025
b6f5318
feat(api): api update
stainless-app[bot] Oct 29, 2025
f28bee7
feat(api): api update
stainless-app[bot] Oct 30, 2025
5f65069
feat(api): api update
stainless-app[bot] Oct 31, 2025
c7d3dda
feat(api): api update
stainless-app[bot] Oct 31, 2025
2c02d15
feat(api): api update
stainless-app[bot] Nov 3, 2025
dfd1f8b
feat(api): api update
stainless-app[bot] Nov 4, 2025
8d0120a
feat(api): api update
stainless-app[bot] Nov 5, 2025
7738ed4
fix(schema): Rename unit price type to avoid naming conflict
stainless-app[bot] Nov 6, 2025
db21295
feat(api): api update
stainless-app[bot] Nov 7, 2025
bf19834
feat(api): api update
stainless-app[bot] Nov 7, 2025
bf4d413
fix(client): multi-value header serialization
stainless-app[bot] Nov 13, 2025
8c81c68
feat(api): api update
stainless-app[bot] Nov 13, 2025
340aeb5
feat(api): api update
stainless-app[bot] Nov 16, 2025
8d40c66
feat(api): api update
stainless-app[bot] Nov 16, 2025
42a3bf2
feat(api): api update
stainless-app[bot] Nov 18, 2025
9928daa
codegen metadata
stainless-app[bot] Nov 24, 2025
16c09ab
feat(api): api update
stainless-app[bot] Nov 25, 2025
c9b8382
fix(client): cancel okhttp call when future cancelled
stainless-app[bot] Nov 26, 2025
a321e4c
feat(api): api update
stainless-app[bot] Dec 2, 2025
c20680a
docs: remove `$` for better copy-pasteabality
stainless-app[bot] Dec 2, 2025
f14a0b8
feat(api): api update
stainless-app[bot] Dec 3, 2025
9a7aa9f
codegen metadata
stainless-app[bot] Dec 4, 2025
66b024c
feat(api): api update
stainless-app[bot] Dec 6, 2025
c911cf7
codegen metadata
stainless-app[bot] Dec 12, 2025
8805300
codegen metadata
stainless-app[bot] Dec 17, 2025
2060d4e
release: 1.10.0
stainless-app[bot] Dec 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
29 changes: 27 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ on:

jobs:
lint:
timeout-minutes: 10
timeout-minutes: 15
name: lint
runs-on: ${{ github.repository == 'stainless-sdks/orb-java' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }}
if: github.event_name == 'push' || github.event.pull_request.head.repo.fork
Expand All @@ -36,8 +36,33 @@ jobs:

- name: Run lints
run: ./scripts/lint

build:
timeout-minutes: 15
name: build
runs-on: ${{ github.repository == 'stainless-sdks/orb-java' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }}
if: github.event_name == 'push' || github.event.pull_request.head.repo.fork

steps:
- uses: actions/checkout@v4

- name: Set up Java
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: |
8
21
cache: gradle

- name: Set up Gradle
uses: gradle/actions/setup-gradle@v4

- name: Build SDK
run: ./scripts/build

test:
timeout-minutes: 10
timeout-minutes: 15
name: test
runs-on: ${{ github.repository == 'stainless-sdks/orb-java' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }}
if: github.event_name == 'push' || github.event.pull_request.head.repo.fork
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish-sonatype.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
distribution: temurin
java-version: |
8
17
21
cache: gradle

- name: Set up Gradle
Expand All @@ -33,7 +33,7 @@ jobs:
export -- GPG_SIGNING_KEY_ID
printenv -- GPG_SIGNING_KEY | gpg --batch --passphrase-fd 3 --import 3<<< "$GPG_SIGNING_PASSWORD"
GPG_SIGNING_KEY_ID="$(gpg --with-colons --list-keys | awk -F : -- '/^pub:/ { getline; print "0x" substr($10, length($10) - 7) }')"
./gradlew publishAndReleaseToMavenCentral -Dorg.gradle.jvmargs="-Xmx8g" --stacktrace -PmavenCentralUsername="$SONATYPE_USERNAME" -PmavenCentralPassword="$SONATYPE_PASSWORD" --no-configuration-cache
./gradlew publishAndReleaseToMavenCentral --stacktrace -PmavenCentralUsername="$SONATYPE_USERNAME" -PmavenCentralPassword="$SONATYPE_PASSWORD" --no-configuration-cache
env:
SONATYPE_USERNAME: ${{ secrets.ORB_SONATYPE_USERNAME || secrets.SONATYPE_USERNAME }}
SONATYPE_PASSWORD: ${{ secrets.ORB_SONATYPE_PASSWORD || secrets.SONATYPE_PASSWORD }}
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
.gradle
.idea
.kotlin
build
build/
codegen.log
kls_database.db
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "1.9.0"
".": "1.10.0"
}
6 changes: 3 additions & 3 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
configured_endpoints: 118
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/orb%2Forb-4f31d46f5ba187fc4d702c9f9f1573dacb891edbd086f935707578d7c4f5fed8.yml
openapi_spec_hash: 25b1019f20a47b8af665aae5f8fd0025
config_hash: 5135e9237207028f293049a77428c775
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/orb%2Forb-59c57f1cbc067a477f6bf673882c28065e01418b86fcff390bba0d4438c58105.yml
openapi_spec_hash: 4da2681664f766985d1c20df40240cd9
config_hash: 05c94c0e6dbeab2c9b554c2e0d6371a0
81 changes: 81 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,86 @@
# Changelog

## 1.10.0 (2025-12-17)

Full Changelog: [v1.9.0...v1.10.0](https://github.com/orbcorp/orb-java/compare/v1.9.0...v1.10.0)

### ⚠ BREAKING CHANGES

* **api:** define shared model ConversionRateConfig

### Features

* add retryable exception ([cf6742e](https://github.com/orbcorp/orb-java/commit/cf6742e0ace7ef26c53fdf1c6ead9f742a326094))
* **api:** api update ([66b024c](https://github.com/orbcorp/orb-java/commit/66b024cd9d56108719ffedb0ef91b94178dd5149))
* **api:** api update ([f14a0b8](https://github.com/orbcorp/orb-java/commit/f14a0b818473f9fe09e299e43c72992dc99cf628))
* **api:** api update ([a321e4c](https://github.com/orbcorp/orb-java/commit/a321e4cb1023069885ecc43f02f35a1ca580d51a))
* **api:** api update ([16c09ab](https://github.com/orbcorp/orb-java/commit/16c09abc0bd756cb2c7c65b5dd987ed135d95fc6))
* **api:** api update ([42a3bf2](https://github.com/orbcorp/orb-java/commit/42a3bf2b3f92450fea64d1fd308c8aef4f705dc4))
* **api:** api update ([8d40c66](https://github.com/orbcorp/orb-java/commit/8d40c665b040c93811cb04523986254db90251c1))
* **api:** api update ([340aeb5](https://github.com/orbcorp/orb-java/commit/340aeb58fff2c96c29b18055963db7e6186fc098))
* **api:** api update ([8c81c68](https://github.com/orbcorp/orb-java/commit/8c81c68e0cc2ec1de0d1bf25f438eb4eb7513e7b))
* **api:** api update ([bf19834](https://github.com/orbcorp/orb-java/commit/bf19834416fab1b4facb56b5bb480a98b4046871))
* **api:** api update ([db21295](https://github.com/orbcorp/orb-java/commit/db212951f87170757554823c153c63723f1919bb))
* **api:** api update ([8d0120a](https://github.com/orbcorp/orb-java/commit/8d0120a97c6c732106ca1f18823e0bcb3a2c3ae3))
* **api:** api update ([dfd1f8b](https://github.com/orbcorp/orb-java/commit/dfd1f8bd061995e3f09660f24d638356ffabbeca))
* **api:** api update ([2c02d15](https://github.com/orbcorp/orb-java/commit/2c02d1554141dfc72791f2c0a9e6801e24ded3e8))
* **api:** api update ([c7d3dda](https://github.com/orbcorp/orb-java/commit/c7d3dda3503f7d9a359f439d8388212a710a2e14))
* **api:** api update ([5f65069](https://github.com/orbcorp/orb-java/commit/5f650699507a73427410d4e30a7694eebabb3376))
* **api:** api update ([f28bee7](https://github.com/orbcorp/orb-java/commit/f28bee7981fa0077a0d93b9061640c6bbdb05098))
* **api:** api update ([b6f5318](https://github.com/orbcorp/orb-java/commit/b6f5318aed1e4b03e46f911ad3f9b199fd6c95bd))
* **api:** api update ([1a45d5d](https://github.com/orbcorp/orb-java/commit/1a45d5d0090f3afda47a434ed4fc2e4d62060e50))
* **api:** api update ([108cdfc](https://github.com/orbcorp/orb-java/commit/108cdfc98f5d0d46721aa7515634c42846eba1ee))
* **api:** api update ([f101f63](https://github.com/orbcorp/orb-java/commit/f101f63b19cda34ea15fe08aba62a8706cc5a8fc))
* **api:** api update ([6c895f2](https://github.com/orbcorp/orb-java/commit/6c895f2348474af8319b87e51db26a28891b7a9c))
* **api:** api update ([84cc66c](https://github.com/orbcorp/orb-java/commit/84cc66cec7668f2de52760b458f5c732914d0995))
* **api:** api update ([ab79480](https://github.com/orbcorp/orb-java/commit/ab794808febc46a53d5baf1e41f0ad7b1ab8d1df))
* **api:** api update ([0f4e585](https://github.com/orbcorp/orb-java/commit/0f4e5853aab9546952e9d80b4c2e50688a8caf6d))
* **api:** api update ([617892e](https://github.com/orbcorp/orb-java/commit/617892e6526e1717415bfa630529ffce50a70b96))
* **api:** api update ([bf412bc](https://github.com/orbcorp/orb-java/commit/bf412bca3a157a0e41fef19a5d915c095b09eda1))
* **api:** api update ([6aa1d53](https://github.com/orbcorp/orb-java/commit/6aa1d5370247b08c937ca7faa9fcacf5b21ed081))
* **api:** api update ([321aa41](https://github.com/orbcorp/orb-java/commit/321aa4197ce9dbc8601ec7578d0f70017e37c2f6))
* **api:** api update ([cf6fd19](https://github.com/orbcorp/orb-java/commit/cf6fd1990dc2781ebc0ab860b135ce4b90a58fa2))
* **api:** api update ([9c8977c](https://github.com/orbcorp/orb-java/commit/9c8977c14697c4907f13e29189a62c2aea441924))
* **api:** api update ([247937e](https://github.com/orbcorp/orb-java/commit/247937ebe3dba64b53c180a9a58460e10cde4a8c))
* **api:** api update ([5d00bf2](https://github.com/orbcorp/orb-java/commit/5d00bf2a8be3610043bbd620eb724d13788fc89a))
* **api:** api update ([05b6a4e](https://github.com/orbcorp/orb-java/commit/05b6a4e2d2e551b8b09168d2a8d6e34851fcd784))
* **api:** api update ([3b2489b](https://github.com/orbcorp/orb-java/commit/3b2489bdb730033a389ec76cc824df8eb351c678))
* **api:** api update ([e90f837](https://github.com/orbcorp/orb-java/commit/e90f837c716a2fe6955df54c844b4320a1a26d8b))
* **api:** define shared model ConversionRateConfig ([13fc2ef](https://github.com/orbcorp/orb-java/commit/13fc2efb464953fc534dbd09ed34b003c17a3d0d))
* **client:** ensure compat with proguard ([83ddd55](https://github.com/orbcorp/orb-java/commit/83ddd55a2e265b3f2426f47868bc5a596509e3a8))
* **client:** expose sleeper option ([427df35](https://github.com/orbcorp/orb-java/commit/427df355df00bafcdb972fbfb758f7cb0646aab6))
* extract minimum composite to type ([3e25650](https://github.com/orbcorp/orb-java/commit/3e256505b03e771aef66c8a435f27a6ec3b9e237))


### Bug Fixes

* **ci:** use java-version 21 for publish step ([b290b3a](https://github.com/orbcorp/orb-java/commit/b290b3a558d6f1b4419975855a22c0f0b8b055e2))
* **client:** cancel okhttp call when future cancelled ([c9b8382](https://github.com/orbcorp/orb-java/commit/c9b8382a9741380a090469881eb5bf242c463a7d))
* **client:** deserialization of empty objects ([1764089](https://github.com/orbcorp/orb-java/commit/1764089476594bd942efe77f15d4744e6c0a01dd))
* **client:** ensure single timer is created per client ([427df35](https://github.com/orbcorp/orb-java/commit/427df355df00bafcdb972fbfb758f7cb0646aab6))
* **client:** incorrect `getPackageVersion` impl ([9bc6ac9](https://github.com/orbcorp/orb-java/commit/9bc6ac99cc3a432ddc30f43dda41d076f4197883))
* **client:** multi-value header serialization ([bf4d413](https://github.com/orbcorp/orb-java/commit/bf4d413ad8025a208cb99ff68f989b7988d906b0))
* **client:** r8 support ([27da721](https://github.com/orbcorp/orb-java/commit/27da7219bb085292eba8cf247a8574689f922300))
* **schema:** Rename unit price type to avoid naming conflict ([7738ed4](https://github.com/orbcorp/orb-java/commit/7738ed44d3ba2df61adb5ef1b7a933b55ab4d5bd))


### Chores

* fix formatting ([a6e527f](https://github.com/orbcorp/orb-java/commit/a6e527f946e40ebbfebc97c4eaeec1900845197a))
* improve formatter performance ([5d37bc1](https://github.com/orbcorp/orb-java/commit/5d37bc171ae17fbfb70c63743afde6b04e29ff1c))
* **internal:** bump ci test timeout ([0e68dd4](https://github.com/orbcorp/orb-java/commit/0e68dd443b79c48810c94749f88cfc2d9286a725))
* **internal:** change some comment formatting ([7e80bfe](https://github.com/orbcorp/orb-java/commit/7e80bfeb93b40dc060dd5947e8e37d4fb68a4955))
* **internal:** codegen related update ([97bd293](https://github.com/orbcorp/orb-java/commit/97bd293da263a5259bac93d2f9d9aeb0f10d5c65))
* **internal:** codegen related update ([3a4300a](https://github.com/orbcorp/orb-java/commit/3a4300ae19b4ad4c9f82056658d88013a35c992e))
* **internal:** codegen related update ([185acb8](https://github.com/orbcorp/orb-java/commit/185acb801fe845d8b33f741e1e1f1e07550fd92f))
* **internal:** codegen related update ([76d269d](https://github.com/orbcorp/orb-java/commit/76d269d0cba09f1150af878d603292b92e003241))
* **internal:** reduce proguard ci logging ([9b4d208](https://github.com/orbcorp/orb-java/commit/9b4d20849c0af2b5945f155aad5a91c338020f56))


### Documentation

* remove `$` for better copy-pasteabality ([c20680a](https://github.com/orbcorp/orb-java/commit/c20680a232316989527ab7da435b6c0baf7885af))

## 1.9.0 (2025-07-26)

Full Changelog: [v1.8.0...v1.9.0](https://github.com/orbcorp/orb-java/compare/v1.8.0...v1.9.0)
Expand Down
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<!-- x-release-please-start-version -->

[![Maven Central](https://img.shields.io/maven-central/v/com.withorb.api/orb-java)](https://central.sonatype.com/artifact/com.withorb.api/orb-java/1.9.0)
[![Maven Central](https://img.shields.io/maven-central/v/com.withorb.api/orb-java)](https://central.sonatype.com/artifact/com.withorb.api/orb-java/1.10.0)

<!-- x-release-please-end -->

Expand All @@ -19,7 +19,7 @@ The REST API documentation can be found on [docs.withorb.com](https://docs.witho
### Gradle

```kotlin
implementation("com.withorb.api:orb-java:1.9.0")
implementation("com.withorb.api:orb-java:1.10.0")
```

### Maven
Expand All @@ -28,7 +28,7 @@ implementation("com.withorb.api:orb-java:1.9.0")
<dependency>
<groupId>com.withorb.api</groupId>
<artifactId>orb-java</artifactId>
<version>1.9.0</version>
<version>1.10.0</version>
</dependency>
```

Expand Down Expand Up @@ -231,6 +231,8 @@ The SDK throws custom unchecked exception types:

- [`OrbIoException`](orb-java-core/src/main/kotlin/com/withorb/api/errors/OrbIoException.kt): I/O networking errors.

- [`OrbRetryableException`](orb-java-core/src/main/kotlin/com/withorb/api/errors/OrbRetryableException.kt): Generic error indicating a failure that could be retried by the client.

- [`OrbInvalidDataException`](orb-java-core/src/main/kotlin/com/withorb/api/errors/OrbInvalidDataException.kt): Failure to interpret successfully parsed data. For example, when accessing a property that's supposed to be required, but the API unexpectedly omitted it from the response.

- [`OrbException`](orb-java-core/src/main/kotlin/com/withorb/api/errors/OrbException.kt): Base class for all exceptions. Most errors will result in one of the previously mentioned ones, but completely generic errors may be thrown using the base class.
Expand Down Expand Up @@ -342,13 +344,13 @@ The SDK uses the standard [OkHttp logging interceptor](https://github.com/square
Enable logging by setting the `ORB_LOG` environment variable to `info`:

```sh
$ export ORB_LOG=info
export ORB_LOG=info
```

Or to `debug` for more verbose logging:

```sh
$ export ORB_LOG=debug
export ORB_LOG=debug
```

## Webhook Verification
Expand All @@ -361,6 +363,12 @@ both of which will raise an error if the signature is invalid.
Note that the `body` parameter must be the raw JSON string sent from the server (do not parse it first).
The `.unwrap()` method can parse this JSON for you.

## ProGuard and R8

Although the SDK uses reflection, it is still usable with [ProGuard](https://github.com/Guardsquare/proguard) and [R8](https://developer.android.com/topic/performance/app-optimization/enable-app-optimization) because `orb-java-core` is published with a [configuration file](orb-java-core/src/main/resources/META-INF/proguard/orb-java-core.pro) containing [keep rules](https://www.guardsquare.com/manual/configuration/usage).

ProGuard and R8 should automatically detect and use the published rules, but you can also manually copy the keep rules if necessary.

## Jackson

The SDK depends on [Jackson](https://github.com/FasterXML/jackson) for JSON serialization/deserialization. It is compatible with version 2.13.4 or higher, but depends on version 2.18.2 by default.
Expand Down
14 changes: 13 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
allprojects {
group = "com.withorb.api"
version = "1.9.0" // x-release-please-version
version = "1.10.0" // x-release-please-version
}

subprojects {
// These are populated with dependencies by `buildSrc` scripts.
tasks.register("format") {
group = "Verification"
description = "Formats all source files."
}
tasks.register("lint") {
group = "Verification"
description = "Verifies all source files are formatted."
}
}
1 change: 0 additions & 1 deletion buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ repositories {
}

dependencies {
implementation("com.diffplug.spotless:spotless-plugin-gradle:7.0.2")
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.20")
implementation("com.vanniktech:gradle-maven-publish-plugin:0.28.0")
}
94 changes: 83 additions & 11 deletions buildSrc/src/main/kotlin/orb.java.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
import com.diffplug.gradle.spotless.SpotlessExtension
import org.gradle.api.tasks.testing.logging.TestExceptionFormat

plugins {
`java-library`
id("com.diffplug.spotless")
}

repositories {
mavenCentral()
}

configure<SpotlessExtension> {
java {
importOrder()
removeUnusedImports()
palantirJavaFormat()
toggleOffOn()
}
}

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(21))
Expand Down Expand Up @@ -53,3 +42,86 @@ tasks.withType<Test>().configureEach {
exceptionFormat = TestExceptionFormat.FULL
}
}

val palantir by configurations.creating
dependencies {
palantir("com.palantir.javaformat:palantir-java-format:2.73.0")
}

fun registerPalantir(
name: String,
description: String,
) {
val javaName = "${name}Java"
tasks.register<JavaExec>(javaName) {
group = "Verification"
this.description = description

classpath = palantir
mainClass = "com.palantir.javaformat.java.Main"

// Avoid an `IllegalAccessError` on Java 9+.
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",
)

// Use paths relative to the current module.
val argumentFile =
project.layout.buildDirectory.file("palantir-$name-args.txt").get().asFile
val lastRunTimeFile =
project.layout.buildDirectory.file("palantir-$name-last-run.txt").get().asFile

// Read the time when this task was last executed for this module (if ever).
val lastRunTime = lastRunTimeFile.takeIf { it.exists() }?.readText()?.toLongOrNull() ?: 0L

// Use a `fileTree` relative to the module's source directory.
val javaFiles = project.fileTree("src") { include("**/*.java") }

// Determine if any files need to be formatted or linted and continue only if there is at least
// one file.
onlyIf { javaFiles.any { it.lastModified() > lastRunTime } }

inputs.files(javaFiles)

doFirst {
// Create the argument file and set the preferred formatting style.
argumentFile.parentFile.mkdirs()
argumentFile.writeText("--palantir\n")

if (name == "lint") {
// For lint, do a dry run, so no files are modified. Set the exit code to 1 (instead of
// the default 0) if any files need to be formatted, indicating that linting has failed.
argumentFile.appendText("--dry-run\n")
argumentFile.appendText("--set-exit-if-changed\n")
} else {
// `--dry-run` and `--replace` (for in-place formatting) are mutually exclusive.
argumentFile.appendText("--replace\n")
}

// Write the modified files to the argument file.
javaFiles.filter { it.lastModified() > lastRunTime }
.forEach { argumentFile.appendText("${it.absolutePath}\n") }
}

doLast {
// Record the last execution time for later up-to-date checking.
lastRunTimeFile.writeText(System.currentTimeMillis().toString())
}

// Pass the argument file using the @ symbol
args = listOf("@${argumentFile.absolutePath}")

outputs.upToDateWhen { javaFiles.none { it.lastModified() > lastRunTime } }
}

tasks.named(name) {
dependsOn(tasks.named(javaName))
}
}

registerPalantir(name = "format", description = "Formats all Java source files.")
registerPalantir(name = "lint", description = "Verifies all Java source files are formatted.")
Loading
Loading