Browse Docs

Java Alerts SDK

There is no separate Java SDK, but you don’t need one.

The Kotlin Multiplatform SDK runs on the JVM and includes EventBuilder, a fluent, refactor-safe builder for constructing events from Java.

Installation

Declare the common artifact (Gradle resolves the JVM variant automatically):

<!-- pom.xml -->
<dependency>
    <groupId>com.apialerts</groupId>
    <artifactId>client</artifactId>
    <version>1.2.0</version>
</dependency>
// build.gradle
implementation 'com.apialerts:client:1.2.0'

Usage from Java

Use EventBuilder for a refactor-safe, named-field experience:

import com.apialerts.client.ApiAlerts;
import com.apialerts.client.EventBuilder;

ApiAlerts.configure("your-api-key");

// message only
ApiAlerts.send(new EventBuilder("Deploy complete").build());

// with optional fields
ApiAlerts.send(new EventBuilder("Deploy complete")
    .channel("releases")
    .event("ci.deploy")
    .title("Deployed")
    .tags(List.of("CI/CD", "Java"))
    .link("https://github.com/apialerts")
    .build());

Attaching data

Pass the data field a plain Map:

ApiAlerts.send(new EventBuilder("New user signed up")
    .data(Map.of("plan", "pro", "count", 5))
    .build());

Values are mapped to JSON heuristically (strings, numbers, booleans, nested maps/lists, null). For full control over the JSON shape, pass a JsonObject - it is itself a Map, so the same .data(...) accepts it.

Awaitable sends

Use ApiAlertsJvm.sendFuture() for a non-blocking CompletableFuture-based API:

import com.apialerts.client.ApiAlertsJvm;
import com.apialerts.client.EventBuilder;

ApiAlertsJvm.sendFuture(new EventBuilder("Deploy complete").build())
    .thenAccept(result ->
        System.out.println("Sent to " + result.getWorkspace() + " (" + result.getChannel() + ")")
    );

// Or block if you need the result synchronously
SendResult result = ApiAlertsJvm.sendFuture(new EventBuilder("Deploy complete").build()).get();

To send to a specific workspace, pass the API key as the second argument:

ApiAlertsJvm.sendFuture(new EventBuilder("Deploy complete").build(), "other-api-key")
    .thenAccept(result -> System.out.println("Sent to " + result.getWorkspace()));

Dependency injection

For Spring (or any DI container), register an ApiAlertsClient with the ApiAlertsJvm.client(...) factory and inject it:

import com.apialerts.client.ApiAlertsClient;
import com.apialerts.client.ApiAlertsJvm;

@Bean
ApiAlertsClient apiAlerts() {
    return ApiAlertsJvm.client("your-api-key");
}
class DeployNotifier {
    private final ApiAlertsClient alerts;

    DeployNotifier(ApiAlertsClient alerts) {
        this.alerts = alerts;
    }

    void onDeploy() {
        // Fire-and-forget
        alerts.send(new EventBuilder("Deploy complete").build(), null);

        // Awaitable (sendAsync is a Kotlin suspend function, so use the bridge)
        ApiAlertsJvm.sendFuture(alerts, new EventBuilder("Deploy complete").build());
    }
}

Recommendation

SituationRecommended approach
Kotlin or KMP projectUse the Kotlin SDK natively
Mixed Java/Kotlin projectAdd the dependency. Works cleanly.
Pure Java backendUse sendFuture() above, or call the REST API directly