Skip to content

Commit

Permalink
refactor: Made openid a KMM library.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoe Maas committed Jul 23, 2024
1 parent 79c3c26 commit 92d1cfa
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 88 deletions.
162 changes: 110 additions & 52 deletions modules/openapi/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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")
}
Expand All @@ -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<KotlinCompileCommon> {
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<KotlinJvmCompile>("compileKotlinJvm") {
dependsOn("openApiGenerate")
}

named("jvmSourcesJar") {
dependsOn("openApiGenerate")
}

publishing {
publications {
create<MavenPublication>("mavenKotlin") {
from(components["kotlin"])
named<Jar>("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<MavenPublication>("mavenKotlin") {
from(components["kotlin"])
}
}
jvmToolchain(21)
}
2 changes: 1 addition & 1 deletion modules/openapi/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
kotlin.code.style=official
#profiles=models-only
profiles=models-only
73 changes: 38 additions & 35 deletions modules/openid-federation-common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,17 @@ kotlin {
}
}

iosX64()
iosArm64()
iosSimulatorArm64()
// iosX64()
// iosArm64()
// iosSimulatorArm64()

jvm()

sourceSets {
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")
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pluginManagement {
includeGroupAndSubgroups("com.google")
}
}
mavenLocal()
mavenCentral()
gradlePluginPortal()
}
Expand All @@ -24,6 +25,7 @@ dependencyResolutionManagement {
includeGroupAndSubgroups("com.google")
}
}
mavenLocal()
mavenCentral()
}
}
Expand Down

0 comments on commit 92d1cfa

Please sign in to comment.