Skip to Content

Java SDK

GoGreen feature flag and experimentation SDK for Java. Evaluate flags, stream real-time updates, and track events with a simple API. Supports OpenFeature  provider.

Requirements

  • Java 11 or later
  • Gradle 8.x (or use the included wrapper: ./gradlew)

Installation

Maven

<dependency> <groupId>com.gogreen</groupId> <artifactId>gogreen-sdk</artifactId> <version>1.0.0</version> </dependency>

Gradle

repositories { mavenCentral() } dependencies { implementation 'com.gogreen:gogreen-sdk:1.0.0' }

Building from source

cd sdk/java ./gradlew build ./gradlew publishToMavenLocal

Then in your project:

repositories { mavenLocal() } dependencies { implementation 'com.gogreen:gogreen-sdk:1.0.0' }

Quick start

import com.gogreen.sdk.*; // Build config (builder pattern) GoGreenConfig config = GoGreenConfig.builder() .sdkKey("your-sdk-key") .envId("your-environment-id") .apiBaseUrl("https://app.gogreenflags.com") .defaultContext(EvaluationContext.builder("user-123").build()) .build(); GoGreenClient client = new GoGreenClient(config); // Wait for initial config (e.g. up to 10 seconds) client.waitForInitialization(10, TimeUnit.SECONDS); // Evaluate flags boolean showNewUI = client.boolVariation("new-ui", false); String plan = client.stringVariation("plan", "free"); double discount = client.numberVariation("discount", 0.0); // With context override EvaluationContext ctx = EvaluationContext.builder("other-user") .putCustom("region", "eu") .build(); boolean flag = client.boolVariationDetail("feature-x", false, ctx); // Track events for experimentation client.track("purchase", Map.of("amount", 99.99)); client.close();

Configuration

OptionDescriptionDefault
sdkKeySDK key (required)
envIdEnvironment ID (required)
apiBaseUrlEvaluation API base URLhttp://localhost:8092
streamUrlSSE stream URLsame as apiBaseUrl
eventsUrlEvents ingestion URLsame as apiBaseUrl
enableStreamingReal-time SSE updatestrue
offlineOffline mode (bootstrap only)false
requestTimeoutMsHTTP timeout (ms)10000
flushIntervalMsEvent flush interval (ms)30000
defaultContextDefault evaluation context (required)
bootstrapBootstrap flags for offlinenull

OpenFeature provider

import com.gogreen.sdk.*; import com.gogreen.sdk.provider.*; import dev.openfeature.sdk.*; GoGreenClient client = new GoGreenClient(config); GoGreenProvider provider = new GoGreenProvider(client); OpenFeatureAPI api = OpenFeatureAPI.getInstance(); api.setProvider(provider); Client ofClient = api.getClient(); boolean value = ofClient.getBooleanValue("my-flag", false);

Testing

Use GoGreenClient.testClient(Map.of("flag-key", value)) for unit tests with no network:

GoGreenClient client = GoGreenClient.testClient(Map.of( "feature-x", true, "ui-theme", "dark", "rate-limit", 50 )); boolean enabled = client.boolVariation("feature-x", false); // returns true

API reference

  • Variation methods: boolVariation, stringVariation, numberVariation, jsonVariation — return the flag value or default.
  • Detail methods: boolVariationDetail, stringVariationDetail, etc. — return EvaluationDetail<T> with value, variationId, reason, ruleIndex, prerequisiteKey.
  • Context: setContext, identify — set evaluation context (user key and custom attributes).
  • Events: track(eventKey, properties) — send custom events for experimentation.
  • Lifecycle: waitForInitialization, initialized, enterOfflineMode, exitOfflineMode, close.