Skip to content

Commit 57d4c74

Browse files
authored
Merge pull request #23 from nats-io/better-targets
Better Targeting: Java 8, 17, 21, 25
2 parents 4f73064 + 530e2b0 commit 57d4c74

24 files changed

+181
-166
lines changed

.github/workflows/build-main.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ jobs:
1010
build:
1111
strategy:
1212
matrix:
13-
jdk: [ 21, 25 ]
13+
tc: [ 8, 17, 21, 25 ]
1414
runs-on: ubuntu-latest
1515
env:
1616
BUILD_EVENT: ${{ github.event_name }}
17-
TARGET_COMPATIBILITY: ${{ matrix.jdk }}
17+
TARGET_COMPATIBILITY: ${{ matrix.tc }}
1818
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
1919
OSSRH_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
2020
SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
@@ -24,7 +24,7 @@ jobs:
2424
- name: Setup JDK
2525
uses: actions/setup-java@v5
2626
with:
27-
java-version: ${{ matrix.jdk }}
27+
java-version: 25
2828
distribution: 'temurin'
2929
- name: Setup Gradle
3030
uses: gradle/actions/setup-gradle@v5
@@ -41,7 +41,7 @@ jobs:
4141
with:
4242
github-token: ${{ secrets.COVERALLS_REPO_TOKEN }}
4343
parallel: true
44-
flag-name: jdk-${{ matrix.jdk }}
44+
flag-name: tc${{ matrix.tc }}
4545
- name: Publish Snapshot
4646
run: ./gradlew -i publishToSonatype
4747

@@ -54,4 +54,4 @@ jobs:
5454
with:
5555
github-token: ${{ secrets.GITHUB_TOKEN }}
5656
parallel-finished: true
57-
carryforward: "jdk-21"
57+
carryforward: "tc8"

.github/workflows/build-pr.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ jobs:
99
build:
1010
strategy:
1111
matrix:
12-
jdk: [ 21, 25 ]
12+
tc: [ 8, 17, 21, 25 ]
1313
runs-on: ubuntu-latest
1414
env:
1515
BUILD_EVENT: ${{ github.event_name }}
16-
TARGET_COMPATIBILITY: ${{ matrix.jdk }}
16+
TARGET_COMPATIBILITY: ${{ matrix.tc }}
1717
steps:
1818
- name: Setup JDK
1919
uses: actions/setup-java@v5
2020
with:
21-
java-version: ${{ matrix.jdk }}
21+
java-version: 25
2222
distribution: 'temurin'
2323
- name: Setup Gradle
2424
uses: gradle/actions/setup-gradle@v5
@@ -35,7 +35,7 @@ jobs:
3535
with:
3636
github-token: ${{ secrets.COVERALLS_REPO_TOKEN }}
3737
parallel: true
38-
flag-name: jdk-${{ matrix.jdk }}
38+
flag-name: tc${{ matrix.tc }}
3939

4040
coveralls-finish:
4141
needs: build
@@ -46,4 +46,4 @@ jobs:
4646
with:
4747
github-token: ${{ secrets.GITHUB_TOKEN }}
4848
parallel-finished: true
49-
carryforward: "jdk-21"
49+
carryforward: "tc8"

.github/workflows/build-release.yml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ jobs:
1111
build:
1212
strategy:
1313
matrix:
14-
jdk: [ 21, 25 ]
14+
tc: [ 8, 17, 21, 25 ]
1515
runs-on: ubuntu-latest
1616
env:
1717
BUILD_EVENT: ${{ github.event_name }}
18-
TARGET_COMPATIBILITY: ${{ matrix.jdk }}
18+
TARGET_COMPATIBILITY: ${{ matrix.tc }}
1919
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
2020
OSSRH_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
2121
SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
@@ -25,17 +25,15 @@ jobs:
2525
- name: Setup JDK
2626
uses: actions/setup-java@v5
2727
with:
28-
java-version: ${{ matrix.jdk }}
28+
java-version: 25
2929
distribution: 'temurin'
3030
- name: Setup Gradle
3131
uses: gradle/actions/setup-gradle@v5
3232
with:
3333
gradle-version: current
3434
- name: Check out code
3535
uses: actions/checkout@v4
36-
- name: Build and Test
37-
run: chmod +x gradlew && ./gradlew clean test
38-
- name: Verify Javadoc
39-
run: ./gradlew javadoc
40-
- name: Verify, Sign and Publish Release
41-
run: ./gradlew -i publishToSonatype closeAndReleaseSonatypeStagingRepository
36+
- name: Prepare Gradle Script
37+
run: chmod +x gradlew && ./gradlew
38+
- name: Build, Sign and Publish Release
39+
run: ./gradlew clean compileJava publishToSonatype closeAndReleaseSonatypeStagingRepository

README.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,34 @@ It has been extracted and repackaged from the JNATS library since it is also use
1111

1212
[![Build Main Badge](https://github.com/nats-io/jnats-json/actions/workflows/build-main.yml/badge.svg?event=push)](https://github.com/nats-io/jnats-json/actions/workflows/build-main.yml)
1313
[![Coverage Status](https://coveralls.io/repos/github/nats-io/jnats-json/badge?branch=main)](https://coveralls.io/github/nats-io/jnats-json?branch=main)
14-
[![Maven JDK 21](https://img.shields.io/maven-central/v/io.nats/jnats-json-jdk21?label=maven-central-jdk21)](https://mvnrepository.com/artifact/io.nats/jnats-json-jdk21)
14+
[![Maven JDK 21](https://img.shields.io/maven-central/v/io.nats/jnats-json?label=maven-central)](https://mvnrepository.com/artifact/io.nats/jnats-json)
1515
[![Maven JDK 25](https://img.shields.io/maven-central/v/io.nats/jnats-json-jdk25?label=maven-central-jdk25)](https://mvnrepository.com/artifact/io.nats/jnats-json-jdk25)
16-
[![Javadoc](http://javadoc.io/badge/io.nats/jnats-json-jdk21.svg?branch=main)](http://javadoc.io/doc/io.nats/jnats-json-jdk21?branch=main)
16+
[![Javadoc](http://javadoc.io/badge/io.nats/jnats-json.svg?branch=main)](http://javadoc.io/doc/io.nats/jnats-json?branch=main)
1717
[![License Apache 2](https://img.shields.io/badge/License-Apache2-blue)](https://www.apache.org/licenses/LICENSE-2.0)
1818

1919
### JDK Version
2020

21-
This project uses Java 21 Language Level api, but builds with both Java 21 and Java 25, so creates two different artifacts.
22-
Both have the same group id `io.nats`, and the same version but have different artifact names.
21+
This project uses Java 8 Language Level api, but builds jars compiled with and targeted for Java 8, 17, 21 and 25.
22+
It creates different artifacts for each. All have the same group id `io.nats` and the same version but have different artifact names.
2323

24-
* The Java 21 artifact id is `jnats-json-jdk21`
25-
* The Java 25 artifact id is `jnats-json-jdk25`
24+
| Java Target Level | artifact id |
25+
|:-------------------:|------------------|
26+
| 8 | jnats-json |
27+
| 17 | jnats-json-jdk17 |
28+
| 21 | jnats-json-jdk21 |
29+
| 25 | jnats-json-jdk25 |
2630

2731
### Dependency Management
2832

2933
The NATS client is available in the Maven central repository,
3034
and can be imported as a standard dependency in your `build.gradle` or `pom.xml` file,
31-
The examples shown use the jdk 21 version, to the jdk 25 version just change the artifact id.
35+
The examples shown use the Jdk 8 version. To use other versions, change the artifact id.
3236

3337
#### Gradle
3438

3539
```groovy
3640
dependencies {
37-
implementation 'io.nats:jnats-json-jdk21:3.0.3'
41+
implementation 'io.nats:jnats-json:3.0.3'
3842
}
3943
```
4044

@@ -60,7 +64,7 @@ repositories {
6064
}
6165
6266
dependencies {
63-
implementation 'io.nats:jnats-json-jdk21:3.0.4-SNAPSHOT'
67+
implementation 'io.nats:jnats-json:3.0.4-SNAPSHOT'
6468
}
6569
```
6670

@@ -69,7 +73,7 @@ dependencies {
6973
```xml
7074
<dependency>
7175
<groupId>io.nats</groupId>
72-
<artifactId>jnats-json-jdk21</artifactId>
76+
<artifactId>jnats-json</artifactId>
7377
<version>3.0.3</version>
7478
</dependency>
7579
```
@@ -103,7 +107,7 @@ If you need a snapshot version, you must enable snapshots and change your depend
103107

104108
<dependency>
105109
<groupId>io.nats</groupId>
106-
<artifactId>jnats-json-jdk21</artifactId>
110+
<artifactId>jnats-json</artifactId>
107111
<version>3.0.4-SNAPSHOT</version>
108112
</dependency>
109113
```

build.gradle

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,24 @@ plugins {
1010
id("signing")
1111
}
1212

13-
def jarVersion = "3.0.3"
13+
def jarVersion = "3.0.4"
1414
group = 'io.nats'
1515

1616
def isRelease = System.getenv("BUILD_EVENT") == "release"
1717
def tc = System.getenv("TARGET_COMPATIBILITY")
18-
def targetId = tc == "25" ? "25" : "21"
19-
def targetJavaVersion = tc == "25" ? JavaVersion.VERSION_25 : JavaVersion.VERSION_21
20-
def artifact = "jnats-json-jdk" + targetId
21-
def bundleName = "io.nats.jnats.json.jdk" + targetId
18+
def targetJavaVersion = tc == null ? JavaVersion.VERSION_1_8 : JavaVersion.toVersion(tc)
19+
def targetId = targetJavaVersion.toString()
20+
def artifact = "jnats-json" + (targetJavaVersion == JavaVersion.VERSION_1_8 ? "" : "-jdk" + targetId)
21+
def bundleName = "io.nats.jnats.json" + (targetJavaVersion == JavaVersion.VERSION_1_8 ? "" : ".jdk" + targetId)
22+
23+
System.out.println("targetCompatibility: " + targetId)
24+
System.out.println("artifact: " + artifact)
25+
System.out.println("bundleName: " + bundleName)
2226

2327
version = isRelease ? jarVersion : jarVersion + "-SNAPSHOT" // version is the variable the gradle uses.
2428

2529
java {
26-
sourceCompatibility = JavaVersion.VERSION_21
30+
sourceCompatibility = JavaVersion.VERSION_1_8
2731
targetCompatibility = targetJavaVersion
2832
withSourcesJar()
2933
withJavadocJar()

src/main/java/io/nats/json/ArrayBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2025-2026 Synadia Communications, Inc.
1+
// Copyright 2025-2026 The NATS Authors
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.

src/main/java/io/nats/json/DateTimeUtils.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
// Copyright 2020-2025 The NATS Authors
2-
//
3-
// Modifications Copyright 2025-2026 Synadia Communications, Inc.
1+
// Copyright 2020-2026 The NATS Authors
42
//
53
// Licensed under the Apache License, Version 2.0 (the "License");
64
// you may not use this file except in compliance with the License.

src/main/java/io/nats/json/Encoding.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
// Copyright 2020-2025 The NATS Authors
2-
//
3-
// Modifications Copyright 2025-2026 Synadia Communications, Inc.
1+
// Copyright 2020-2026 The NATS Authors
42
//
53
// Licensed under the Apache License, Version 2.0 (the "License");
64
// you may not use this file except in compliance with the License.
@@ -20,6 +18,7 @@
2018
import org.jspecify.annotations.NonNull;
2119
import org.jspecify.annotations.Nullable;
2220

21+
import java.io.UnsupportedEncodingException;
2322
import java.net.URLDecoder;
2423
import java.nio.charset.Charset;
2524
import java.nio.charset.StandardCharsets;
@@ -305,7 +304,7 @@ public static StringBuilder jsonEncode(@NonNull StringBuilder sb, @Nullable Stri
305304
* @param source the input
306305
* @return the decoded URI
307306
*/
308-
public static String uriDecode(@NonNull String source) {
309-
return URLDecoder.decode(source.replace("+", "%2B"), StandardCharsets.UTF_8);
307+
public static String uriDecode(@NonNull String source) throws UnsupportedEncodingException {
308+
return URLDecoder.decode(source.replace("+", "%2B"), StandardCharsets.UTF_8.name());
310309
}
311310
}

src/main/java/io/nats/json/JsonParseException.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
// Copyright 2023 The NATS Authors
2-
//
3-
// Modifications Copyright 2025-2026 Synadia Communications, Inc.
1+
// Copyright 2023-2026 The NATS Authors
42
//
53
// Licensed under the Apache License, Version 2.0 (the "License");
64
// you may not use this file except in compliance with the License.

src/main/java/io/nats/json/JsonParser.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
// Copyright 2023 The NATS Authors
2-
//
3-
// Modifications Copyright 2025-2026 Synadia Communications, Inc.
1+
// Copyright 2023-2026 The NATS Authors
42
//
53
// Licensed under the Apache License, Version 2.0 (the "License");
64
// you may not use this file except in compliance with the License.

0 commit comments

Comments
 (0)