Skip to content

Commit 8eba3d7

Browse files
authored
feat!: Kotlin Multiplatform support (#148)
Signed-off-by: Bence Hornák <[email protected]>
1 parent af1377e commit 8eba3d7

File tree

77 files changed

+4282
-1380
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+4282
-1380
lines changed

.editorconfig

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ ij_kotlin_method_call_chain_wrap = normal
6868
ij_kotlin_method_parameters_new_line_after_left_paren = true
6969
ij_kotlin_method_parameters_right_paren_on_new_line = true
7070
ij_kotlin_method_parameters_wrap = on_every_item
71-
ij_kotlin_name_count_to_use_star_import = 5
72-
ij_kotlin_name_count_to_use_star_import_for_members = 3
71+
ij_kotlin_name_count_to_use_star_import = 999
72+
ij_kotlin_name_count_to_use_star_import_for_members = 999
7373
ij_kotlin_packages_to_use_import_on_demand = unset
7474
ij_kotlin_parameter_annotation_wrap = off
7575
ij_kotlin_space_after_comma = true
@@ -130,4 +130,7 @@ max_line_length=120
130130

131131
# Ignore max line for kotlin test files, the same as Detekt.
132132
[**/{test,androidTest}/**/*.kt]
133-
max_line_length=off
133+
max_line_length=off
134+
135+
[*.kts]
136+
max_line_length = off

.github/workflows/ci.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,9 @@ jobs:
1414
steps:
1515
- name: Checkout
1616
uses: actions/checkout@v4
17+
18+
# For browser tests
19+
- uses: browser-actions/setup-chrome@v1
20+
1721
- name: Run checks
1822
run: ./gradlew check --no-daemon --stacktrace

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33

44
.idea
55
local.properties
6+
.kotlin

CONTRIBUTING.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,20 @@ Manual formatting is done by invoking
1616
./gradlew ktlintFormat
1717
```
1818

19+
## Testing
20+
21+
Prerequisite for browser tests: Install Google Chrome (or Google Chrome headless)
22+
23+
To run tests on all supported platforms:
24+
```
25+
./gradlew allTests
26+
```
27+
28+
To run all verifications:
29+
```
30+
./gradlew check
31+
```
32+
1933
## Releases
2034

2135
This repo uses _Release Please_ to release packages. Release Please sets up a running PR that tracks all changes in the library, and maintains the versions according to [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/), generated when [PRs are merged](https://github.com/amannn/action-semantic-pull-request), based on the PR title. The semantics of the PR title are enforced by the `lint-pr.yml` workflow. When Release Please's running PR is merged, a new release is created, and the associated artifacts are published.

README.md

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,70 @@
3535

3636
### Requirements
3737

38-
- The Android minSdk version supported is: `21`.
38+
The following [Kotlin Multiplatform Targets](https://www.jetbrains.com/help/kotlin-multiplatform-dev/multiplatform-dsl-reference.html#targets) are supported:
3939

40-
Note that this library is intended to be used in a mobile context, and has not been evaluated for use in other types of applications (e.g. server applications).
40+
| Supported | Platform | Supported versions |
41+
|-----------|----------------------|--------------------------------------------------------------------------------|
42+
|| Android | SDK 21+ |
43+
|| JVM | JDK 11+ |
44+
|| Native | Linux x64 |
45+
|| Native | [Other native targets](https://kotlinlang.org/docs/native-target-support.html) |
46+
|| Javascript (Node.js) | |
47+
|| Javascript (Browser) | |
48+
|| Wasm | |
4149

42-
### Install
4350

44-
#### Maven Central
51+
Note that this library adheres to the
52+
[Static Context Paradigm](https://openfeature.dev/docs/reference/concepts/sdk-paradigms), so it is
53+
intended to be used on the **client side** (i.e. mobile apps, web apps and desktop apps), and has
54+
not been evaluated for use in other types of applications (e.g. server applications).
4555

46-
Installation via Maven Central is preferred, using the following dependency:
56+
### Installation
57+
58+
Installation is preferred via Maven Central.
59+
60+
#### In Android projects
61+
62+
> [!IMPORTANT]
63+
> Before version 0.6.0 the Maven artifact's id was `android-sdk`. When upgrading to 0.6.0 or higher
64+
> please do make sure to use the new artifact id, which is `kotlin-sdk`.
4765
4866
<!-- x-release-please-start-version -->
67+
4968
```kotlin
5069
dependencies {
51-
api("dev.openfeature:android-sdk:0.5.3")
70+
api("dev.openfeature:kotlin-sdk:0.5.3")
5271
}
5372
```
73+
<!-- x-release-please-end -->
74+
75+
#### In multiplatform projects
76+
77+
<!-- x-release-please-start-version -->
78+
```kotlin
79+
kotlin {
80+
sourceSets {
81+
commonMain.dependencies {
82+
api("dev.openfeature:kotlin-sdk:0.5.3")
83+
}
84+
}
85+
}
86+
```
87+
<!-- x-release-please-end -->
88+
5489

5590
### Usage
5691

92+
> [!NOTE]
93+
> In version 0.6.0 the base package name has changed from `dev.openfeature.sdk` to
94+
> `dev.openfeature.kotlin.sdk`. When upgrading to 0.6.0 or higher please update your imports
95+
> accordingly.
96+
>
97+
> **Example:** `import dev.openfeature.sdk.EvaluationContext` ->
98+
> `import dev.openfeature.kotlin.sdk.EvaluationContext`.
99+
57100
```kotlin
58-
coroutineScope.launch(Dispatchers.IO) {
101+
coroutineScope.launch(Dispatchers.Default) {
59102
// configure a provider, wait for it to complete its initialization tasks
60103
OpenFeatureAPI.setProviderAndWait(customProvider)
61104
val client = OpenFeatureAPI.getClient()
@@ -90,7 +133,7 @@ If the provider you're looking for hasn't been created yet, see the [develop a p
90133
Once you've added a provider as a dependency, it can be registered with OpenFeature like this:
91134

92135
```kotlin
93-
coroutineScope.launch(Dispatchers.IO) {
136+
coroutineScope.launch(Dispatchers.Default) {
94137
OpenFeatureAPI.setProviderAndWait(MyProvider())
95138
}
96139
```
@@ -195,7 +238,7 @@ viewModelScope.launch {
195238
viewModelScope.launch {
196239
OpenFeatureAPI.setProviderAndWait(
197240
MyFeatureProvider(),
198-
Dispatchers.IO,
241+
Dispatchers.Default,
199242
myEvaluationContext
200243
)
201244
}

0 commit comments

Comments
 (0)