Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update to kotlin 2.0.20, update libraries #78

Merged
merged 7 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ For iOS only, use the [OpenIdConnectClient Swift Package](https://github.com/kal

You can find the full Api documentation [here](https://kalinjul.github.io/kotlin-multiplatform-oidc/).

Library dependency versions:

| kmp-oidc version | kotlin version | ktor version |
|------------------|----------------|--------------|
| 0.11.+ | 1.9.23 | 2.3.7 |
| 0.12.+ | 2.0.20 | 2.3.+ |
| future version | 2.0.20 | 3.0.+ |
Note that while the library may work with other kotlin/ktor versions, proceed at your own risk.

# Dependency
Add the dependency to your commonMain sourceSet (KMP) / Android dependencies (android only):
```kotlin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,10 @@ package org.publicvalue.convention

import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.getByType
import org.jetbrains.compose.ComposeExtension

class ComposeMultiplatformConventionPlugin : Plugin<Project> {
override fun apply(target: Project) = with(target) {
pluginManager.apply("org.jetbrains.compose")
configureCompose()
}
}

fun Project.configureCompose() {
with(extensions.getByType<ComposeExtension>()) {
kotlinCompilerPlugin.set(libs.versions.composeCompiler.get())
pluginManager.apply("org.jetbrains.kotlin.plugin.compose")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.gradle.configurationcache.extensions.capitalized
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.getByType
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType

Expand Down Expand Up @@ -48,3 +49,16 @@ private fun Project.addKspDependencyForAllTargets(
}
}
}

fun KotlinMultiplatformExtension.addParcelizeAnnotation(annotationClass: String) {
androidTarget {
// https://youtrack.jetbrains.com/issue/KT-66448
@OptIn(ExperimentalKotlinGradlePluginApi::class)
compilerOptions {
freeCompilerArgs.addAll(
"-P",
"plugin:org.jetbrains.kotlin.parcelize:additionalAnnotation=${annotationClass}"
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.publicvalue.convention.config.configureAndroidTarget
import org.publicvalue.convention.config.configureIosTargets
import org.publicvalue.convention.config.configureKotlin

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ fun Project.configureKotlin() {
extensions.configure<KotlinMultiplatformExtension> {
targets.all {
compilations.all {
compilerOptions.configure {
freeCompilerArgs.add("-Xexpect-actual-classes")
compileTaskProvider.configure {
compilerOptions {
freeCompilerArgs.add("-Xexpect-actual-classes")
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package org.publicvalue.convention.config

import org.gradle.api.JavaVersion
import org.gradle.kotlin.dsl.get
import org.gradle.kotlin.dsl.withType
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
import org.publicvalue.convention.libs

@OptIn(ExperimentalKotlinGradlePluginApi::class)
fun KotlinMultiplatformExtension.configureAndroidTarget() {
androidTarget {
compilations.all {
kotlinOptions {
jvmTarget = JavaVersion.toVersion(project.libs.versions.jvmTarget.get()).toString()
}
compilerOptions {
jvmTarget.set(JvmTarget.fromTarget((project.libs.versions.jvmTarget.get())))
}
}
}
Expand All @@ -26,4 +29,12 @@ fun KotlinMultiplatformExtension.configureIosTargets(baseName: String? = null) {
isStatic = true
}
}
}

fun KotlinMultiplatformExtension.exportKdoc() {
targets.withType<KotlinNativeTarget> {
compilations["main"].compileTaskProvider.configure {
compilerOptions.freeCompilerArgs.add("-Xexport-kdoc")
}
}
}
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.android.library) apply false
alias(libs.plugins.composeMultiplatform) apply false
alias(libs.plugins.compose.compiler) apply false
alias(libs.plugins.ksp) apply false
alias(libs.plugins.kmp) apply false
alias(libs.plugins.multiplatform.swiftpackage) apply false
Expand Down
60 changes: 28 additions & 32 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,51 +8,50 @@ jvmTarget = "17"
agp = "8.2.2"

#https://github.com/JetBrains/compose-multiplatform
compose-multiplatform = "1.5.11"
kotlin = "1.9.23"
compose-multiplatform = "1.6.11"
kotlin = "2.0.20"
# https://github.com/google/ksp
ksp = "1.9.23-1.0.20"
ksp = "2.0.20-1.0.25"
kotlin-inject = "0.6.3"

#https://mvnrepository.com/artifact/org.jetbrains.compose.compiler/compiler
composeCompiler = "1.5.10.1"

# https://developer.android.com/jetpack/androidx/releases/activity
androidxActivity = "1.8.2"
androidxActivity = "1.9.2"
# https://developer.android.com/jetpack/androidx/releases/appcompat
androidxAppCompat = "1.6.1"
androidxAppCompat = "1.7.0"

coreKtx = "1.12.0"
coreKtx = "1.13.1"
#https://developer.android.com/jetpack/androidx/releases/arch-core
coreTesting = "2.2.0"

kotlinxCoroutines = "1.7.3"
kotlinxSerialization = "1.6.0"
kotlinxCoroutines = "1.8.1"
kotlinxSerialization = "1.7.1"

# https://github.com/Kotlin/kotlinx-datetime
kotlinxDatetime = "0.5.0"
kotlinxDatetime = "0.6.0"
# https://github.com/Kotlin/kotlinx-atomicfu
kotlinxAtomicfu = "0.23.1"
kotlinxAtomicfu = "0.24.0"

# https://github.com/slackhq/circuit/releases
circuit = "0.16.0"
circuit = "0.22.2"
sqldelight = "2.0.1"

okhttp = "4.12.0"
ktor = "2.3.7"

nexus-publish-plugin = "1.3.0"
multiplatform-swiftpackage = "2.2.0"
multiplatform-swiftpackage = "2.2.1"
swiftklib = "0.5.1"
dokka = "1.9.10"
# https://developer.android.com/jetpack/androidx/releases/security
securityCryptoKtx = "1.1.0-alpha06"

assertk = "0.28.1"

[libraries]
androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidxActivity" }
androidx-appcompat = { module = "androidx.appcompat:appcompat", version.ref = "androidxAppCompat" }
androidx-core-ktx = { module = "androidx.core:core-ktx", version.ref = "coreKtx" }
androidx-browser = { module = "androidx.browser:browser", version = "1.7.0" }
androidx-browser = { module = "androidx.browser:browser", version = "1.8.0" }
androidx-security-crypto-ktx = { module = "androidx.security:security-crypto-ktx", version.ref = "securityCryptoKtx" }
androidx-security-crypto = { module = "androidx.security:security-crypto", version.ref = "securityCryptoKtx" }

Expand All @@ -63,15 +62,6 @@ kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serializa
kotlin-inject-compiler = { module = "me.tatarka.inject:kotlin-inject-compiler-ksp", version.ref = "kotlin-inject" }
kotlin-inject-runtime = { module = "me.tatarka.inject:kotlin-inject-runtime", version.ref = "kotlin-inject" }

# Build logic dependencies
android-gradlePlugin = { module = "com.android.tools.build:gradle", version.ref = "agp" }
kotlin-gradlePlugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
compose-gradlePlugin = { module = "org.jetbrains.compose:compose-gradle-plugin", version.ref = "compose-multiplatform" }
#licensee-gradlePlugin = { module = "app.cash.licensee:licensee-gradle-plugin", version.ref = "licensee" }
nexusPublish-gradlePlugin = { module = "io.github.gradle-nexus:publish-plugin", version.ref = "nexus-publish-plugin" }
multiplatform-swiftpackage-gradlePlugin = { module = "io.github.luca992.multiplatform-swiftpackage:io.github.luca992.multiplatform-swiftpackage.gradle.plugin", version.ref = "multiplatform-swiftpackage" }
dokka-gradlePlugin = { module = "org.jetbrains.dokka:org.jetbrains.dokka.gradle.plugin", version.ref = "dokka" }

kotlinx-datetime = { module = "org.jetbrains.kotlinx:kotlinx-datetime", version.ref = "kotlinxDatetime" }
kotlinx-atomicfu = { module = "org.jetbrains.kotlinx:atomicfu", version.ref = "kotlinxAtomicfu" }

Expand All @@ -98,24 +88,30 @@ ktor-server-cio = { module = "io.ktor:ktor-server-cio", version.ref = "ktor" }
ktor-server-jvm = { module = "io.ktor:ktor-server-jvm", version.ref = "ktor" }
ktor-server-netty = { module = "io.ktor:ktor-server-netty", version.ref = "ktor" }

okhttp = { module = "com.squareup.okhttp3:okhttp", version.ref = "okhttp" }
assertk = { module = "com.willowtreeapps.assertk:assertk", version.ref = "assertk" }

# Build logic dependencies
android-gradlePlugin = { module = "com.android.tools.build:gradle", version.ref = "agp" }
kotlin-gradlePlugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
compose-gradlePlugin = { module = "org.jetbrains.compose:compose-gradle-plugin", version.ref = "compose-multiplatform" }
nexusPublish-gradlePlugin = { module = "io.github.gradle-nexus:publish-plugin", version.ref = "nexus-publish-plugin" }
multiplatform-swiftpackage-gradlePlugin = { module = "io.github.luca992.multiplatform-swiftpackage:io.github.luca992.multiplatform-swiftpackage.gradle.plugin", version.ref = "multiplatform-swiftpackage" }
dokka-gradlePlugin = { module = "org.jetbrains.dokka:org.jetbrains.dokka.gradle.plugin", version.ref = "dokka" }

# sample app libraries
circuit-foundation = { module = "com.slack.circuit:circuit-foundation", version.ref = "circuit" }
circuit-gestureNavigation = { module = "com.slack.circuit:circuitx-gesture-navigation", version.ref = "circuit" }
circuit-overlay = { module = "com.slack.circuit:circuit-overlay", version.ref = "circuit" }
circuit-retained = { module = "com.slack.circuit:circuit-retained", version.ref = "circuit" }
circuit-runtime = { module = "com.slack.circuit:circuit-runtime", version.ref = "circuit" }

okhttp = { module = "com.squareup.okhttp3:okhttp", version.ref = "okhttp" }

# test
assertk = "com.willowtreeapps.assertk:assertk:0.27.0"

# settings
russhwolf-multiplatformsettings = "com.russhwolf:multiplatform-settings:1.1.0"

[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }
android-library = { id = "com.android.library", version.ref = "agp" }
composeMultiplatform = { id = "org.jetbrains.compose", version.ref = "compose-multiplatform" }
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
kmp = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin"}
sqldelight = { id = "app.cash.sqldelight", version.ref = "sqldelight" }
Expand Down
4 changes: 2 additions & 2 deletions oidc-appsupport/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import com.android.build.gradle.internal.tasks.factory.dependsOn
import org.jetbrains.kotlin.gradle.plugin.mpp.Framework
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
import org.publicvalue.convention.config.configureIosTargets
import org.publicvalue.convention.config.exportKdoc
import java.nio.file.Files
import java.util.stream.Collectors.toList
import kotlin.io.path.name
Expand Down Expand Up @@ -97,9 +98,8 @@ kotlin {
}
}

exportKdoc()
targets.withType<KotlinNativeTarget> {
compilations["main"].compilerOptions.options.freeCompilerArgs.add("-Xexport-kdoc")

binaries.withType<Framework> {
export(projects.oidcCore)
export(projects.oidcTokenstore)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package org.publicvalue.multiplatform.oidc.appsupport
import android.app.Activity
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.webkit.CookieManager
import android.webkit.WebChromeClient
Expand Down Expand Up @@ -130,7 +129,7 @@ class HandleRedirectActivity : ComponentActivity() {
intent.launchUrl(this, Uri.parse(url))
}

override fun onNewIntent(intent: Intent?) {
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
setIntent(intent)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ actual class PlatformCodeAuthFlow(
client: OpenIdConnectClient,
) : CodeAuthFlow(client) {

override suspend fun getAuthorizationCode(request: AuthCodeRequest): AuthCodeResponse {
actual override suspend fun getAuthorizationCode(request: AuthCodeRequest): AuthCodeResponse {
val intent = Intent(
context,
HandleRedirectActivity::class.java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fun <Input, Output> ComponentActivity.registerForActivityResultSuspend(

class ActivityResultLauncherSuspend<Input, Output>(
val delegate: ActivityResultLauncher<Input>,
val resultFlow: MutableStateFlow<Output?>
val resultFlow: MutableStateFlow<Output?>,
): ActivityResultLauncher<Input>() {

override fun launch(input: Input, options: ActivityOptionsCompat?) {
Expand All @@ -50,7 +50,5 @@ class ActivityResultLauncherSuspend<Input, Output>(
delegate.unregister()
}

override fun getContract(): ActivityResultContract<Input, *> {
return delegate.contract
}
override val contract: ActivityResultContract<Input, *> = delegate.contract
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package org.publicvalue.multiplatform.oidc.appsupport

import org.publicvalue.multiplatform.oidc.flows.AuthCodeResponse
import org.publicvalue.multiplatform.oidc.flows.CodeAuthFlow
import org.publicvalue.multiplatform.oidc.types.AuthCodeRequest

expect class PlatformCodeAuthFlow: CodeAuthFlow
expect class PlatformCodeAuthFlow: CodeAuthFlow {
// in kotlin 2.0, we need to implement methods in expect classes
override suspend fun getAuthorizationCode(request: AuthCodeRequest): AuthCodeResponse
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ actual class PlatformCodeAuthFlow(
// required for swift (no default argument support)
constructor(client: OpenIdConnectClient) : this(client = client, ephemeralBrowserSession = false)

override suspend fun getAuthorizationCode(request: AuthCodeRequest): AuthCodeResponse = wrapExceptions {
actual override suspend fun getAuthorizationCode(request: AuthCodeRequest): AuthCodeResponse = wrapExceptions {
val authResponse = suspendCoroutine { continuation ->
val nsurl = NSURL.URLWithString(request.url.toString())
if (nsurl != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ actual class PlatformCodeAuthFlow(
var PORT = 8080
}

override suspend fun getAuthorizationCode(request: AuthCodeRequest): AuthCodeResponse {
actual override suspend fun getAuthorizationCode(request: AuthCodeRequest): AuthCodeResponse {

val redirectUrl = request.config.redirectUri?.let { Url(it) }
if (redirectUrl?.port != PORT || !redirectUrl.isLocalhost()) {
Expand Down
5 changes: 2 additions & 3 deletions oidc-core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import org.publicvalue.convention.config.configureIosTargets
import org.publicvalue.convention.config.exportKdoc

plugins {
id("org.publicvalue.convention.kotlin.multiplatform")
Expand Down Expand Up @@ -46,7 +47,5 @@ kotlin {
}
}

targets.withType<org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget> {
compilations["main"].compilerOptions.options.freeCompilerArgs.add("-Xexport-kdoc")
}
exportKdoc()
}
5 changes: 2 additions & 3 deletions oidc-crypto/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import org.publicvalue.convention.config.configureIosTargets
import org.publicvalue.convention.config.exportKdoc

plugins {
id("org.publicvalue.convention.kotlin.multiplatform")
Expand Down Expand Up @@ -43,9 +44,7 @@ kotlin {
}
}

targets.withType<org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget> {
compilations["main"].compilerOptions.options.freeCompilerArgs.add("-Xexport-kdoc")
}
exportKdoc()
}

swiftklib {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ suspend fun TokenStore.getTokens(): OauthTokens? {
}
}

@ExperimentalOpenIdConnect
val TokenStore.tokensFlow: Flow<OauthTokens?>
get() = combine(accessTokenFlow, refreshTokenFlow, idTokenFlow) { accessToken, refreshToken, idToken ->
if (accessToken != null) {
Expand Down
1 change: 1 addition & 0 deletions playground-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.android.library) apply false
alias(libs.plugins.composeMultiplatform) apply false
alias(libs.plugins.compose.compiler) apply false
alias(libs.plugins.ksp) apply false
alias(libs.plugins.kmp) apply false
}
Loading
Loading