https://kotlinlang.org
Join Slack
Hi folks, How do I run a custom gradle task that only runs after the build tasks completes in a KMM ...
k

Kwabena Berko

about 3 years ago
Hi folks, How do I run a custom gradle task that only runs after the build tasks completes in a KMM project?
tasks.register("copySomething", Copy::class) {
   println("How Do I Run This Task After Build Completes?")
}
k
j
m
  • 3
  • 15
  • 1149
What is the best practice to refresh OAuth access tokens using a refresh token in OkHttp? I have the...
l

Lukasz Kalnik

about 3 years ago
What is the best practice to refresh OAuth access tokens using a refresh token in OkHttp? I have the following setup, but it's failing in case of parallel calls. The
synchronized(lock)
doesn't seem to prevent the second call to try to refresh the token as well.
val okHttpClient = OkHttpClient.Builder()
    .addInterceptor(AccessTokenInterceptor(oAuthRepository))
    .authenticator(RefreshTokenAuthenticator(oAuthRepository))
    .build()

val lock = Any()

private class AccessTokenInterceptor(
    private val oAuthRepository: OAuthRepository
) : Interceptor {

    override fun intercept(chain: Chain): Response {
        synchronized(lock) {
            val token = oAuthRepository.accessToken

            val request = chain.request().newBuilder().apply {
                if (token != null) header("Authorization", "Bearer $token")
            }.build()
            return chain.proceed(request)
        }
    }
}

private class RefreshTokenAuthenticator(
    private val oAuthRepository: OAuthRepository
) : Authenticator {

    override fun authenticate(route: Route?, response: Response): Request? {
        if (response.responseCount >= 2) return null

        synchronized(lock) {
            return runBlocking {
                oAuthRepository.refreshTokens().map {
                    oAuthRepository.accessToken
                }
            }.fold(
                ifLeft = { null },
                ifRight = {
                    it?.let { token ->
                        response.request.newBuilder()
                            .header("Authorization", "Bearer $token")
                            .build()
                    }
                }
            )
        }
    }
}
l
y
+2
  • 4
  • 8
  • 1148
Is there any example on how to use gradle version catalog toml where the BOM of spring boot is defin...
h

Humphrey

over 2 years ago
Is there any example on how to use gradle version catalog toml where the BOM of spring boot is defined as platform so I don’t need to specify any version of the dependencies that is already provided by that BOM? And how do I override/pin just one version let’s say for the H2 database (com.h2databsse) to an older version? And add additional dependencies that are not there in the spring boot BOM?
h
v
c
  • 3
  • 8
  • 1145
I'm getting when applying the Kotlin Multiplatform plugin as well as the Android library plugin… ```...
c

CLOVIS

over 2 years ago
I'm getting when applying the Kotlin Multiplatform plugin as well as the Android library plugin…
Could not create an instance of type org.jetbrains.kotlin.gradle.plugin.mpp.KotlinAndroidTarget.
> Could not generate a decorated class for type KotlinAndroidTarget.
   > com/android/build/gradle/api/BaseVariant
The error message doesn't help me at all, where should I look for to fix this?
c
m
  • 2
  • 19
  • 1142
how can I use `value class` in a multiplatform project? Previously I used `inline class` but I see i...
p

Piotr Krzemiński

almost 3 years ago
how can I use
value class
in a multiplatform project? Previously I used
inline class
but I see it’s deprecated now. Using
value class
produces an error “Value classes without @JvmInline annotation are not supported yet” and I cannot use
@JvmInline
in a multiplatform project obviously. What’s the recommended path forward? Keep using
inline class
? What’s the plan of proper multiplatform support for
value class
? Once we clarify all of it, I’ll propose some changes to the docs: https://kotlinlang.org/docs/inline-classes.html
✅ 1
p
h
+2
  • 4
  • 9
  • 1142
'io.ktor.client.call.NoTransformationFoundException: No transformation found: class io.ktor.utils.io...
p

Praveen Kumar

over 2 years ago
'io.ktor.client.call.NoTransformationFoundException: No transformation found: class io.ktor.utils.io.ByteBufferChannel (Kotlin reflection is not available) -> interface java.util.List (Kotlin reflection is not available) with response from https://cmms.auswegprime.com/Api/get_plant_engineer_status_list: status: 200 ' I get this error while receiving data from server
p
j
+2
  • 4
  • 29
  • 1141
Is there any uniform approach for scanning QR-codes on multiplatform? I need iOS/Android/Desktop JVM
j

jQrgen

about 2 years ago
Is there any uniform approach for scanning QR-codes on multiplatform? I need iOS/Android/Desktop JVM
j
a
+3
  • 5
  • 9
  • 1140
Hi, how to update composable when a list changes by `rember { mutableStateOf(mutableListOf<Int&gt...
l

Lance Gao

almost 4 years ago
Hi, how to update composable when a list changes by
rember { mutableStateOf(mutableListOf<Int>())}
?
l
m
c
  • 3
  • 9
  • 1140
&gt; 'capitalize(): String' is deprecated. Use replaceFirstChar instead what is the thinking here? `...
j

Jonathan Ellis

over 3 years ago
'capitalize(): String' is deprecated. Use replaceFirstChar instead
what is the thinking here?
replaceFirstChar { if (it.isLowerCase()) it.titlecase() else it.toString() }
is a lot clunkier
😕 1
j
m
+3
  • 5
  • 18
  • 1139
Hello, I am discovering the new `plugins` declaration. Applying below in the root Gradle file ```pl...
n

nuhkoca

over 3 years ago
Hello, I am discovering the new
plugins
declaration. Applying below in the root Gradle file
plugins {
    id("com.android.application") version "7.2" apply false
    id("com.android.library") version "7.2" apply false
}
But I also need to apply
Gradle
plugin in
buildSrc
so I have this in there
implementation("com.android.tools.build:gradle:7.2.0")
but then IDE throws an exception
Error resolving plugin [id: ‘com.android.application’, version: ‘7.2.0’, apply: false]
> The request for this plugin could not be satisfied because the plugin is already on the classpath with an unknown version, so compatibility cannot be checked.
How do I have the same plugin works for the both places?
n
v
a
  • 3
  • 8
  • 1133
Previous353637Next

kotlinlang

A modern programming language that makes developers happier.

Powered by