Java implementation of the OpenFeature SDK
Go to file
github-actions[bot] f5ceeb06b4
chore(main): release 1.3.1 (#331)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2023-03-28 13:33:51 -04:00
.github/workflows chore(deps): update github/codeql-action digest to f9c159f (#359) 2023-03-28 09:23:03 +00:00
docs chore: Add release plz (#66) 2022-09-13 11:36:42 -07:00
release Add release instructions & build caches 2022-06-24 00:04:35 -05:00
src fix: validate list content to be values (#350) 2023-03-22 16:46:53 +00:00
test-harness@2d4c63c800 chore: update cuke submodule, tests (#231) 2023-01-10 09:28:17 -08:00
.clomonitor.yml chore: Document where to find our SBOMs (#124) 2022-10-06 16:33:11 -04:00
.gitattributes Skeleton implementation of the java sdk 2022-04-20 21:12:09 -07:00
.gitignore Handle null provider, all author code in try/catch 2022-08-15 08:57:55 -04:00
.gitmodules chore: add integration tests (#77) 2022-09-20 09:48:34 -04:00
.release-please-manifest.json chore(main): release 1.3.1 (#331) 2023-03-28 13:33:51 -04:00
CHANGELOG.md chore(main): release 1.3.1 (#331) 2023-03-28 13:33:51 -04:00
CODEOWNERS chore: update CODEOWNERS 2023-03-23 15:24:11 -04:00
CONTRIBUTING.md Add a contributing.md 2022-06-17 21:05:12 -07:00
LICENSE Add Apache2.0 license 2022-04-29 15:21:59 -04:00
README.md chore(main): release 1.3.1 (#331) 2023-03-28 13:33:51 -04:00
checkstyle-suppressions.xml chore: fix issues with compilation on later JDKs (#178) 2022-11-20 23:25:45 -08:00
checkstyle.xml chore: fix issues with compilation on later JDKs (#178) 2022-11-20 23:25:45 -08:00
pom.xml chore(main): release 1.3.1 (#331) 2023-03-28 13:33:51 -04:00
release-please-config.json chore: add changelog sections (#320) 2023-03-08 12:33:13 -08:00
renovate.json chore: renovate regex manager to monitor test-harness version (#238) 2023-01-12 12:42:10 -05:00
spec_finder.py Keep tests in line with spec changes 2022-08-29 11:18:46 -07:00
spotbugs-exclusions.xml chore: fix issues with compilation on later JDKs (#178) 2022-11-20 23:25:45 -08:00
version.txt chore(main): release 1.3.1 (#331) 2023-03-28 13:33:51 -04:00

README.md

OpenFeature SDK for Java

Maven Central javadoc Project Status: Active – The project has reached a stable, usable state and is being actively developed. Specification Known Vulnerabilities on-merge codecov CII Best Practices

This is the Java implementation of OpenFeature, a vendor-agnostic abstraction library for evaluating feature flags.

We support multiple data types for flags (numbers, strings, booleans, objects) as well as hooks, which can alter the lifecycle of a flag evaluation.

This library is intended to be used in server-side contexts and has not been evaluated for use in mobile devices.

Usage

While Boolean provides the simplest introduction, we offer a variety of flag types.

import dev.openfeature.sdk.Structure;

class MyClass {
    public UI booleanExample() {
        // Should we render the redesign? Or the default webpage? 
        if (client.getBooleanValue("redesign_enabled", false)) {
            return render_redesign();
        }
        return render_normal();
    }

    public Template stringExample() {
        // Get the template to load for the custom new homepage
        String template = client.getStringValue("homepage_template", "default-homepage.html");
        return render_template(template);
    }

    public List<HomepageModule> numberExample() {
        // How many modules should we be fetching?
        Integer count = client.getIntegerValue("module-fetch-count", 4);
        return fetch_modules(count);
    }

    public HomepageModule structureExample() {
        Structure obj = client.getObjectValue("hero-module", previouslyDefinedDefaultStructure);
        return HomepageModule.builder()
                .title(obj.getValue("title"))
                .body(obj.getValue("description"))
                .build();
    }
}

For complete documentation, visit: https://docs.openfeature.dev/docs/category/concepts

Requirements

  • Java 8+ (compiler target is 1.8)

Installation

Add it to your build

Maven

<dependency>
    <groupId>dev.openfeature</groupId>
    <artifactId>sdk</artifactId>
    <version>1.3.1</version>
</dependency>

If you would like snapshot builds, this is the relevant repository information:

<repositories>
    <repository>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
        <id>sonartype</id>
        <name>Sonartype Repository</name>
        <url>https://s01.oss.sonatype.org/content/repositories/snapshots/</url>
    </repository>
</repositories>

Gradle

dependencies {
    implementation 'dev.openfeature:sdk:1.3.1'
}

Configure it

To configure it, you'll need to add a provider to the global singleton OpenFeatureAPI. From there, you can generate a Client which is usable by your code. While you'll likely want a provider for your specific backend, we've provided a NoOpProvider, which simply returns the default passed in.

class MyApp {
    public void example(){
        OpenFeatureAPI api = OpenFeatureAPI.getInstance();
        api.setProvider(new NoOpProvider());
        Client client = api.getClient();
        // Now use your `client` instance to evaluate some feature flags!
    }
}

Contacting us

We hold regular meetings which you can see here.

We are also present on the #openfeature channel in the CNCF slack.

Developing

Integration tests

The continuous integration runs a set of gherkin integration tests using flagd. These tests do not run with the default maven profile. If you'd like to run them locally, you can start the flagd testbed with

docker run -p 8013:8013 ghcr.io/open-feature/flagd-testbed:latest

and then run

mvn test -P integration-test

Releasing

See releasing.

Software Bill of Materials (SBOM)

We publish SBOMs with all of our releases as of 0.3.0. You can find them in Maven Central alongside the artifacts.

Contributors

Thanks so much to our contributors.

Pictures of the folks who have contributed to the project

Made with contrib.rocks.