This is an OpenFeature provider implementation for GrowthBook's Java SDK. It allows you to use GrowthBook as a feature flag provider with the OpenFeature SDK.
GrowthBook is an open source Feature Flagging and Experimentation platform built for data teams, engineers, and product managers. Get Started using GrowthBook today.
This version of the GrowthBook provider works with Java 8 and above.
First, install the Growthbook OpenFeature provider for Java as a dependency in your application.
<dependency>
<groupId>com.github.growthbook</groupId>
<artifactId>growthbook-openfeature-provider-java</artifactId>
<version>0.0.1</version> <!-- use current version number -->
</dependency>implementation group: 'com.github.growthbook', name: 'growthbook-openfeature-provider-java', version: '0.0.1'
// Use current version number in place of 0.0.1.
Uses the following dependencies:
dev.openfeature:sdk:1.12.2
com.github.growthbook:growthbook-sdk-java:0.9.92// Configure GrowthBook
Options options = Options.builder()
.apiHost("https://cdn.growthbook.io")
.clientKey("YOUR_CLIENT_KEY")
.build();
// Initialize provider
GrowthBookProvider provider = new GrowthBookProvider(options);
// Set the provider in OpenFeature
OpenFeatureAPI.getInstance().setProvider(provider);
// Get a client
Client client = OpenFeatureAPI.getInstance().getClient();
// Create context with user attributes
EvaluationContext context = EvaluationContext.builder()
.targetingKey("user-123")
.set("country", "US")
.build();
// Evaluate features
boolean enabled = client.getBooleanValue("my-feature", false, context);
// Clean up
provider.shutdown();See GrowthBookExample.java for a complete example of how to use the provider. For information on using the OpenFeature client please refer to the OpenFeature Documentation.
- Supports all OpenFeature evaluation types (boolean, string, integer, double, object)
- Full integration with GrowthBook's targeting and feature evaluation capability
- Thread-safe evaluation
The provider automatically converts OpenFeature's EvaluationContext to GrowthBook's UserContext:
targetingKeybecomes the user ID- Context attributes are converted to GrowthBook attributes
- Supports all value types (boolean, number, string, object, array)
The provider is thread-safe and can be used in multi-threaded environments.
- Initialize the provider early in your application lifecycle
- Reuse the OpenFeature client instance
- Include relevant user attributes in the context
- Handle potential exceptions during evaluation
- Clean up resources using the shutdown method
Contributions are welcome! Please feel free to submit a Pull Request.