Skip to content

Update samples #365

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

Open
wants to merge 2 commits into
base: release-0.8.0
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions samples/grpc-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
plugins {
kotlin("jvm") version "2.1.10"
kotlin("plugin.serialization") version "2.1.10"
id("org.jetbrains.kotlinx.rpc.plugin") version "0.6.0"
id("org.jetbrains.kotlinx.rpc.plugin") version "0.7.0"
id("com.google.protobuf") version "0.9.5"
}

Expand All @@ -22,9 +22,9 @@ kotlin {
}

dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-rpc-grpc-core:0.5.1-grpc-39")
implementation("org.jetbrains.kotlinx:kotlinx-rpc-grpc-core:0.7.0-grpc-56")
implementation("ch.qos.logback:logback-classic:1.5.18")
implementation("io.grpc:grpc-netty:1.71.0")
implementation("io.grpc:grpc-netty:1.73.0")
}

rpc {
Expand Down
2 changes: 1 addition & 1 deletion samples/grpc-app/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.2-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
5 changes: 2 additions & 3 deletions samples/ktor-all-platforms-app/composeApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig

plugins {
Expand All @@ -17,9 +16,9 @@ plugins {
}

kotlin {
@OptIn(ExperimentalWasmDsl::class)
@OptIn(org.jetbrains.kotlin.gradle.ExperimentalWasmDsl::class)
wasmJs {
moduleName = "composeApp"
outputModuleName = "composeApp"
browser {
val projectDirPath = project.projectDir.path
commonWebpackConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import kotlinx.rpc.krpc.ktor.client.installKrpc
import kotlinx.rpc.krpc.ktor.client.rpc
import kotlinx.rpc.krpc.ktor.client.rpcConfig
import kotlinx.rpc.krpc.serialization.json.json
import kotlinx.rpc.krpc.streamScoped
import kotlinx.rpc.withService
import ktor_all_platforms_app.composeapp.generated.resources.Res
import ktor_all_platforms_app.composeapp.generated.resources.compose_multiplatform
Expand Down
18 changes: 9 additions & 9 deletions samples/ktor-all-platforms-app/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
[versions]
kotlin = "2.1.21"
kotlin = "2.2.0"

agp = "8.9.1"
android-compileSdk = "35"
agp = "8.11.0-alpha07"
android-compileSdk = "36"
android-minSdk = "24"
android-targetSdk = "35"
android-targetSdk = "36"
androidx-activityCompose = "1.10.1"
androidx-appcompat = "1.7.0"
androidx-appcompat = "1.7.1"
androidx-constraintlayout = "2.2.1"
androidx-core-ktx = "1.16.0"
androidx-espresso-core = "3.6.1"
androidx-material = "1.12.0"
androidx-test-junit = "1.2.1"
compose = "1.7.8"
compose-plugin = "1.8.0-SNAPSHOT+pull-5245"
compose = "1.8.3"
compose-plugin = "1.8.2"
junit = "4.13.2"
ktor = "3.1.2"
ktor = "3.1.3"
logback = "1.5.18"
serialization = "1.8.1"
coroutines = "1.10.2"
kotlinx-rpc = "0.7.0"
kotlinx-rpc = "0.8.0"

[libraries]
# kotlin
Expand Down
Binary file modified samples/ktor-all-platforms-app/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.2-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
4 changes: 2 additions & 2 deletions samples/ktor-all-platforms-app/gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ case "$( uname )" in #(
NONSTOP* ) nonstop=true ;;
esac

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
CLASSPATH="\\\"\\\""


# Determine the Java command to use to start the JVM.
Expand Down Expand Up @@ -213,7 +213,7 @@ DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \
org.gradle.wrapper.GradleWrapperMain \
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
"$@"

# Stop when "xargs" is not available.
Expand Down
4 changes: 2 additions & 2 deletions samples/ktor-all-platforms-app/gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ goto fail
:execute
@rem Setup the command line

set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
set CLASSPATH=


@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*

:end
@rem End local scope for the variables with windows NT shell
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fun Application.module() {
}
}

registerService<UserService> { ctx -> UserServiceImpl(ctx) }
registerService<UserService> { UserServiceImpl() }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import kotlin.coroutines.CoroutineContext

class UserServiceImpl(override val coroutineContext: CoroutineContext) : UserService {
class UserServiceImpl : UserService {
override suspend fun hello(user: String, userData: UserData): String {
return "Nice to meet you $user, how is it in ${userData.address}?"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ import kotlinx.rpc.krpc.ktor.client.installKrpc
import kotlinx.rpc.krpc.ktor.client.rpc
import kotlinx.rpc.krpc.ktor.client.rpcConfig
import kotlinx.rpc.krpc.serialization.json.json
import kotlinx.rpc.krpc.streamScoped
import kotlinx.rpc.withService
import kotlin.test.Test
import kotlin.test.assertEquals

class ApplicationTest {
@Test
fun testRoot() = testApplication {
application {
module()
}

val service = createClient {
installKrpc()
}.rpc("/api") {
Expand Down
2 changes: 1 addition & 1 deletion samples/ktor-all-platforms-app/shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
*/

import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig

plugins {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
*/

import kotlinx.coroutines.flow.Flow
import kotlinx.rpc.RemoteService
import kotlinx.rpc.annotations.Rpc
import kotlinx.serialization.Serializable

Expand All @@ -14,7 +13,7 @@ data class UserData(
)

@Rpc
interface UserService : RemoteService {
interface UserService {
suspend fun hello(user: String, userData: UserData): String

fun subscribeToNews(): Flow<String>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import kotlinx.rpc.krpc.ktor.client.rpc
import kotlinx.rpc.krpc.ktor.client.rpcConfig
import kotlinx.rpc.krpc.serialization.json.json

suspend fun createRpcClient(): RpcClient {
fun createRpcClient(): RpcClient {
return HttpClient(OkHttp) {
installKrpc()
}.rpc {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package kotlinx.rpc.sample.ui

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.CoroutineScope
import kotlinx.rpc.sample.data.createRpcClient
import kotlinx.rpc.sample.ui.state.WelcomeData
import kotlinx.coroutines.Dispatchers
Expand All @@ -15,49 +16,40 @@ import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch
import kotlinx.rpc.RpcClient
import kotlinx.rpc.krpc.streamScoped
import kotlinx.rpc.withService
import kotlinx.rpc.sample.MyService
import kotlinx.rpc.sample.UserData

class AppViewModel : ViewModel() {
private var rpcClient: RpcClient? = null
private var apiService: MyService? = null
private val rpcClient: RpcClient = createRpcClient()
private val apiService: MyService = rpcClient.withService<MyService>()

private val _uiState = MutableStateFlow<WelcomeData?>(null)
val uiState: StateFlow<WelcomeData?> = _uiState

init {
viewModelScope.launch(Dispatchers.IO) {
rpcClient = createRpcClient()
rpcClient?.let {
apiService = it.withService()
fetchData()
}
fetchData()
}
}

private fun fetchData() {
viewModelScope.launch(Dispatchers.IO) {
delay(2000)
val greetingDeferred = async {
apiService?.hello(
"Alex",
UserData("Berlin", "Smith")
)
}

val serverGreeting = greetingDeferred.await()

val allNews: MutableList<String> = mutableListOf()
apiService?.subscribeToNews()?.collect {
allNews += it

val sendNews = allNews.toMutableList() // fix ConcurrentModificationException
serverGreeting?.let {
_uiState.value = WelcomeData(serverGreeting, sendNews)
}
}
private suspend fun CoroutineScope.fetchData() {
delay(2000)
val greetingDeferred = async {
apiService.hello(
"Alex",
UserData("Berlin", "Smith")
)
}

val serverGreeting = greetingDeferred.await()

val allNews: MutableList<String> = mutableListOf()
apiService.subscribeToNews().collect {
allNews += it

val sendNews = allNews.toMutableList() // fix ConcurrentModificationException
_uiState.value = WelcomeData(serverGreeting, sendNews)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
package kotlinx.rpc.sample

import kotlinx.coroutines.flow.Flow
import kotlinx.rpc.RemoteService
import kotlinx.rpc.annotations.Rpc

@Rpc
interface MyService : RemoteService {
interface MyService {
suspend fun hello(user: String, userData: UserData): String

fun subscribeToNews(): Flow<String>
Expand Down
14 changes: 7 additions & 7 deletions samples/ktor-android-app/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
[versions]
agp = "8.9.1"
kotlin = "2.1.21"
agp = "8.11.0-alpha07"
kotlin = "2.2.0"
androidx-activityCompose = "1.10.1"
androidx-appcompat = "1.7.0"
androidx-appcompat = "1.7.1"
androidx-constraintlayout = "2.2.1"
androidx-core-ktx = "1.16.0"
androidx-test-junit = "1.2.1"
compose = "1.7.8"
compose = "1.8.3"
compose-plugin = "1.5.14" # https://mvnrepository.com/artifact/androidx.compose.compiler/compiler
compose-bom = "2025.04.00"
compose-bom = "2025.06.01"
material3 = "1.3.2"
junit = "4.13.2"
ktor = "3.1.2"
ktor = "3.2.0"
kotlinx-serialization-json = "1.8.1"
kotlinx-coroutines-core = "1.10.2"
logback = "1.5.18"
kotlinx-rpc = "0.7.0"
kotlinx-rpc = "0.8.0"

[libraries]
# kotlin
Expand Down
Binary file modified samples/ktor-android-app/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.2-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
4 changes: 2 additions & 2 deletions samples/ktor-android-app/gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ case "$( uname )" in #(
NONSTOP* ) nonstop=true ;;
esac

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
CLASSPATH="\\\"\\\""


# Determine the Java command to use to start the JVM.
Expand Down Expand Up @@ -213,7 +213,7 @@ DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \
org.gradle.wrapper.GradleWrapperMain \
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
"$@"

# Stop when "xargs" is not available.
Expand Down
4 changes: 2 additions & 2 deletions samples/ktor-android-app/gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ goto fail
:execute
@rem Setup the command line

set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
set CLASSPATH=


@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*

:end
@rem End local scope for the variables with windows NT shell
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fun Application.module() {
}
}

registerService<MyService> { ctx -> MyServiceImpl(ctx) }
registerService<MyService> { MyServiceImpl() }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import kotlin.coroutines.CoroutineContext

class MyServiceImpl(override val coroutineContext: CoroutineContext) : MyService {
class MyServiceImpl : MyService {
override suspend fun hello(user: String, userData: UserData): String {
return "Nice to meet you $user, how is it in ${userData.address}?"
}
Expand All @@ -22,4 +22,4 @@ class MyServiceImpl(override val coroutineContext: CoroutineContext) : MyService
}
}
}
}
}
Loading
Loading