Что я делаю Я хочу сгенерировать из моего серверного проекта клиент openApi как зависимость Jar Kotlin и импортировать его в мой клиентский проект.
Вот сборка серверного градиента для достижения этапа 'генерация клиента/упаковка jar/локальная публикация maven':
Генерация внутреннего клиента:
Код: Выделить всё
tasks.register("generateKotlinClient", org.openapitools.generator.gradle.plugin.tasks.GenerateTask::class) {
generatorName.set("kotlin")
inputSpec.set("$rootDir/src/main/resources/api/api.yaml")
outputDir.set(layout.buildDirectory.dir("generated/grimoire-server-client").get().asFile.path)
invokerPackage.set("com.com.corbz.grimoire.backend.client")
packageName.set("com.com.corbz.grimoire.backend.client")
apiPackage.set("com.com.corbz.grimoire.backend.client.api")
modelPackage.set("com.com.corbz.grimoire.backend.client.model")
generateApiDocumentation.set(false)
generateModelDocumentation.set(false)
generateApiTests.set(false)
generateModelTests.set(false)
configOptions.set(
mapOf(
"sourceFolder" to "."
)
)
}
tasks.register("packageClientJar", Jar::class) {
group = "build"
val generatedClientDir = layout.buildDirectory.dir("generated/grimoire-server-client/com").get().asFile
from(generatedClientDir)
archiveBaseName.set("grimoire-backend-client")
archiveVersion.set("1.0.0")
destinationDirectory.set(layout.buildDirectory.dir("libs").get().asFile)
}
publishing {
publications {
create("grimoireBackendClient") {
groupId = "com.corbz"
artifactId = "grimoire-backend-client"
version = "1.0.0"
artifact(tasks.named("packageClientJar").get()) {
builtBy(tasks.named("packageClientJar"))
}
}
}
repositories {
maven {
name = "local"
url = uri("${System.getProperty("user.home")}/.m2/repository")
}
}
}
Код: Выделить всё
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.kotlin.compose)
}
android {
namespace = "com.corbz.grmoire.android"
compileSdk = 35
defaultConfig {
applicationId = "com.corbz.grmoire.android"
minSdk = 24
targetSdk = 35
versionCode = 1
versionName = "1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = "17"
}
buildFeatures {
compose = true
}
}
dependencies {
// Business dependencies --------------------------
implementation(libs.grimoire.backend.client)
implementation(libs.moshi)
implementation(libs.moshi.kotlin)
// ------------------------------------------------
}
Код: Выделить всё
package com.corbz.grmoire.android.config
import android.app.Application
import dagger.hilt.android.HiltAndroidApp
import com.corbz.grimoire.backend.client.model.*
@HiltAndroidApp
class GrimoireApplication: Application() {
}
Код: Выделить всё
@file:Suppress(
"ArrayInDataClass",
"EnumEntryName",
"RemoveRedundantQualifierName",
"UnusedImport"
)
package com.com.corbz.grimoire.backend.client.model
import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
/**
*
*
* @param code Unique identifier for the grimoire.
* @param creationDate The creation date of the grimoire.
* @param lastUpdateDate The last update date of the grimoire.
*/
data class GrimoireDto (
/* Unique identifier for the grimoire. */
@Json(name = "code")
val code: kotlin.String,
/* The creation date of the grimoire. */
@Json(name = "creationDate")
val creationDate: java.time.OffsetDateTime,
/* The last update date of the grimoire. */
@Json(name = "lastUpdateDate")
val lastUpdateDate: java.time.OffsetDateTime
) {
}
Я даже пытаюсь сгенерировать с помощью генератора Android (для меня он должен работать с мультиплатформой Kotlin, но это было «для науки»), но проблема все еще остается тот то же самое.
Не могли бы вы помочь разобраться, что не так с моей генерацией/импортом? Я хотел бы импортировать этот клиент, чтобы избежать ручного написания клиентского вызова серверной части.
Заранее спасибо, ребята!
Подробнее здесь: https://stackoverflow.com/questions/793 ... ed-in-my-a