From 92d1cfa1bb44d1b45ce44894c85d0c6193a80bcd Mon Sep 17 00:00:00 2001 From: Zoe Maas Date: Tue, 23 Jul 2024 14:37:08 +0200 Subject: [PATCH] refactor: Made openid a KMM library. --- modules/openapi/build.gradle.kts | 162 ++++++++++++------ modules/openapi/gradle.properties | 2 +- .../com/sphereon/oid/fed/openapi/openapi.yaml | 0 .../openid-federation-common/build.gradle.kts | 73 ++++---- settings.gradle.kts | 2 + 5 files changed, 151 insertions(+), 88 deletions(-) rename modules/openapi/src/{main => commonMain}/kotlin/com/sphereon/oid/fed/openapi/openapi.yaml (100%) diff --git a/modules/openapi/build.gradle.kts b/modules/openapi/build.gradle.kts index d8e95628..64c3a4ab 100644 --- a/modules/openapi/build.gradle.kts +++ b/modules/openapi/build.gradle.kts @@ -1,5 +1,8 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompileCommon +import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile + plugins { - kotlin("jvm") version "2.0.0" + kotlin("multiplatform") version "2.0.0" id("org.openapi.generator") version "7.7.0" id("maven-publish") } @@ -17,66 +20,121 @@ repositories { mavenCentral() } -dependencies { - implementation("io.ktor:ktor-client-core:$ktorVersion") - implementation("io.ktor:ktor-client-content-negotiation:$ktorVersion") - implementation("io.ktor:ktor-serialization-kotlinx-json:$ktorVersion") - implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.0") - implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:1.7.0") -} +kotlin { + tasks { + withType { + dependsOn("openApiGenerate") + } + named("sourcesJar") { + dependsOn("openApiGenerate") + } + } + jvm { + tasks { + openApiGenerate { + val openApiPackage: String by project + generatorName.set("kotlin") + packageName.set("com.sphereon.oid.fed.openapi") + apiPackage.set("$openApiPackage.api") + modelPackage.set("$openApiPackage.models") + inputSpec.set("$projectDir/src/commonMain/kotlin/com/sphereon/oid/fed/openapi/openapi.yaml") + library.set("multiplatform") + outputDir.set("$projectDir/build/generated") + configOptions.set( + mapOf( + "dateLibrary" to "string" + ) + ) -openApiGenerate { - val openApiPackage: String by project - generatorName.set("kotlin") - packageName.set("com.sphereon.oid.fed.openapi") - apiPackage.set("$openApiPackage.api") - modelPackage.set("$openApiPackage.models") - inputSpec.set("$projectDir/src/main/kotlin/com/sphereon/oid/fed/openapi/openapi.yaml") - library.set("multiplatform") - outputDir.set("$projectDir/build/generated") -configOptions.set( - mapOf( - "dateLibrary" to "string" - ) - ) + if (isModelsOnlyProfile) { + globalProperties.set( + configOptions.get().plus( + mapOf( + "models" to "" + ) + ) + ) + } + } - if (isModelsOnlyProfile) { - globalProperties.set( - configOptions.get().plus( - mapOf( - "models" to "" - ) - ) - ) - } -} + named("compileKotlinJvm") { + dependsOn("openApiGenerate") + } + named("jvmSourcesJar") { + dependsOn("openApiGenerate") + } -publishing { - publications { - create("mavenKotlin") { - from(components["kotlin"]) + named("jvmJar") { + dependsOn("compileKotlinJvm") + archiveBaseName.set("openapi") + duplicatesStrategy = DuplicatesStrategy.EXCLUDE + from(configurations.kotlinCompilerClasspath.get().map { if (it.isDirectory) it else zipTree(it) }) + from("$projectDir/build/classes/kotlin/jvm/main") + } } } -} -tasks.compileKotlin { - dependsOn(tasks.openApiGenerate) -} + js { + tasks { + named("compileKotlinJs") { + dependsOn("openApiGenerate") + } + named("jsSourcesJar") { + dependsOn("openApiGenerate") + } + } + nodejs() + } + + iosX64 { + tasks { + named("compileKotlinIosX64") { + dependsOn("openApiGenerate") + } + named("iosX64SourcesJar") { + dependsOn("openApiGenerate") + } + } + } + iosArm64 { + tasks { + named("compileKotlinIosArm64") { + dependsOn("openApiGenerate") + } + named("iosArm64SourcesJar") { + dependsOn("openApiGenerate") + } + } + } + iosSimulatorArm64 { + tasks { + named("compileKotlinIosSimulatorArm64") { + dependsOn("openApiGenerate") + } + named("iosSimulatorArm64SourcesJar") { + dependsOn("openApiGenerate") + } + } + } -tasks.jar { - dependsOn(tasks.compileKotlin) - duplicatesStrategy = DuplicatesStrategy.EXCLUDE - archiveBaseName.set(project.name) - from(configurations.runtimeClasspath.get().map { if (it.isDirectory) it else zipTree(it) }) - from("$projectDir/build/classes/kotlin/main") + sourceSets { + val commonMain by getting { + kotlin.srcDir("build/generated/src/commonMain/kotlin") + dependencies { + implementation("io.ktor:ktor-client-core:$ktorVersion") + implementation("io.ktor:ktor-client-content-negotiation:$ktorVersion") + implementation("io.ktor:ktor-serialization-kotlinx-json:$ktorVersion") + implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.0") + } + } + } } -kotlin { - sourceSets.main { - kotlin.srcDirs( - "$projectDir/build/generated/src/commonMain/kotlin" - ) +publishing { + publications { + create("mavenKotlin") { + from(components["kotlin"]) + } } - jvmToolchain(21) } diff --git a/modules/openapi/gradle.properties b/modules/openapi/gradle.properties index 08d60d78..33cf166a 100644 --- a/modules/openapi/gradle.properties +++ b/modules/openapi/gradle.properties @@ -1,2 +1,2 @@ kotlin.code.style=official -#profiles=models-only +profiles=models-only diff --git a/modules/openapi/src/main/kotlin/com/sphereon/oid/fed/openapi/openapi.yaml b/modules/openapi/src/commonMain/kotlin/com/sphereon/oid/fed/openapi/openapi.yaml similarity index 100% rename from modules/openapi/src/main/kotlin/com/sphereon/oid/fed/openapi/openapi.yaml rename to modules/openapi/src/commonMain/kotlin/com/sphereon/oid/fed/openapi/openapi.yaml diff --git a/modules/openid-federation-common/build.gradle.kts b/modules/openid-federation-common/build.gradle.kts index 0f402dfd..39241a06 100644 --- a/modules/openid-federation-common/build.gradle.kts +++ b/modules/openid-federation-common/build.gradle.kts @@ -40,9 +40,9 @@ kotlin { } } - iosX64() - iosArm64() - iosSimulatorArm64() +// iosX64() +// iosArm64() +// iosSimulatorArm64() jvm() @@ -50,7 +50,7 @@ kotlin { val commonMain by getting { dependencies { implementation("com.sphereon.oid.fed:openapi:0.1.0-SNAPSHOT") - runtimeOnly("io.ktor:ktor-client-core:$ktorVersion") + implementation("io.ktor:ktor-client-core:$ktorVersion") runtimeOnly("io.ktor:ktor-client-logging:$ktorVersion") runtimeOnly("io.ktor:ktor-client-cio:$ktorVersion") implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.0") @@ -88,37 +88,40 @@ kotlin { } } - val iosMain by creating { - dependsOn(commonMain) - } - val iosX64Main by getting { - dependsOn(iosMain) - dependencies { - implementation("io.ktor:ktor-client-core-iosx64:$ktorVersion") - implementation("io.ktor:ktor-client-cio-iosx64:$ktorVersion") - } - } - val iosArm64Main by getting { - dependsOn(iosMain) - dependencies { - implementation("io.ktor:ktor-client-core-iosarm64:$ktorVersion") - implementation("io.ktor:ktor-client-cio-iosarm64:$ktorVersion") - } - } - val iosSimulatorArm64Main by getting { - dependsOn(iosMain) - dependencies { - implementation("io.ktor:ktor-client-core-iossimulatorarm64:$ktorVersion") - implementation("io.ktor:ktor-client-cio-iossimulatorarm64:$ktorVersion") - } - } - - val iosTest by creating { - dependsOn(commonTest) - dependencies { - implementation(kotlin("test")) - } - } +// val iosMain by creating { +// dependsOn(commonMain) +// dependencies { +// +// } +// } +// val iosX64Main by getting { +// //dependsOn(iosMain) +// dependencies { +// implementation("io.ktor:ktor-client-core-iosx64:$ktorVersion") +// implementation("io.ktor:ktor-client-cio-iosx64:$ktorVersion") +// } +// } +// val iosArm64Main by getting { +// dependsOn(iosX64Main) +// dependencies { +// implementation("io.ktor:ktor-client-core-iosarm64:$ktorVersion") +// implementation("io.ktor:ktor-client-cio-iosarm64:$ktorVersion") +// } +// } +// val iosSimulatorArm64Main by getting { +// dependsOn(iosX64Main) +// dependencies { +// implementation("io.ktor:ktor-client-core-iossimulatorarm64:$ktorVersion") +// implementation("io.ktor:ktor-client-cio-iossimulatorarm64:$ktorVersion") +// } +// } +// +// val iosTest by creating { +// dependsOn(commonTest) +// dependencies { +// implementation(kotlin("test")) +// } +// } val jsMain by getting { dependencies { diff --git a/settings.gradle.kts b/settings.gradle.kts index 3a09b2cc..62604efb 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -10,6 +10,7 @@ pluginManagement { includeGroupAndSubgroups("com.google") } } + mavenLocal() mavenCentral() gradlePluginPortal() } @@ -24,6 +25,7 @@ dependencyResolutionManagement { includeGroupAndSubgroups("com.google") } } + mavenLocal() mavenCentral() } }