Császár Ákos
03/07/2024, 1:58 PMkhalid64927
03/08/2024, 3:08 AMCsászár Ákos
03/08/2024, 7:33 AMplugins {
alias(libs.plugins.multiplatform.swiftpackage)
alias(libs.plugins.app.cash.sqldelight)
alias(libs.plugins.detektPlugin)
kotlin("plugin.serialization") version libs.versions.kotlin
kotlin("native.cocoapods")
kotlin("multiplatform")
id("com.android.library")
id("kotlin-parcelize")
id("maven-publish")
}
kotlin {
// --------------------------------- TARGETS ---------------------------------
applyDefaultHierarchyTemplate()
androidTarget {
compilations.all {
kotlinOptions {
jvmTarget = "1.8"
}
}
publishLibraryVariants("release", "debug")
}
iosX64()
iosArm64()
iosSimulatorArm64()
tvosArm64()
tvosSimulatorArm64()
js(IR) {
moduleName = ""
browser {
webpackTask {
mainOutputFileName.set("")
output.library = ""
}
testTask {
useKarma {
useChrome()
}
}
}
generateTypeScriptDefinitions()
binaries.library()
binaries.executable()
// add sourceMaps to web
binaries.withType<JsIrBinary>().all {
linkTask.configure {
kotlinOptions {
sourceMap = true
sourceMapEmbedSources = "always"
}
}
}
}
targets.forEach { target ->
target.compilations.all {
kotlinOptions {
freeCompilerArgs += listOf("-Xexpect-actual-classes")
}
}
}
// --------------------------------- SOURCE SETS ---------------------------------
sourceSets {
val commonMain by getting {
dependencies {
api(libs.koin.core)
}
}
val commonMobile by creating {
dependsOn(commonMain)
dependencies {
...
}
}
appleMain {
dependsOn(commonMain)
dependsOn(commonMobile)
dependencies {
....
}
}
androidMain {
dependsOn(commonMobile)
dependencies {
api(libs.koin.android)
}
}
jsMain {
dependencies {
...
}
}
commonTest {
dependencies {
implementation(kotlin("test"))
}
}
val androidUnitTest by getting {
dependencies {
...
}
}
}
// --------------------------------- PUBLISHING ---------------------------------
cocoapods {
summary = ""
homepage = ""
ios.deploymentTarget = "14.1"
framework {
baseName = ""
}
}
multiplatformSwiftPackage {
packageName("")
swiftToolsVersion("5.3")
targetPlatforms {
iOS { v("13") }
macOS { v("10_15") }
tvOS { v("13") }
}
}
val publicationsFromMainHost = listOf(js()).map { it.name } + "kotlinApiLib"
publishing {
publications {
matching { it.name in publicationsFromMainHost }.all {
val targetPublication = this@all
tasks.withType<AbstractPublishToMaven>()
.matching {
it.publication == targetPublication
}
.configureEach { onlyIf { findProperty("isMainHost") == "true" } }
}
repositories {
maven(url = "repoUrl") {
name = "name"
credentials {
username = "user"
password = "password"
}
}
}
register<MavenPublication>("release") {
groupId = "my.group.id"
artifactId = mavenArtifactId
version = libVersion
afterEvaluate {
from(components["release"])
}
}
}
}
}
project.tasks.findByPath("jsProductionLibraryCompileSync")?.dependsOn("jsBrowserProductionWebpack")
android {
defaultConfig {
aarMetadata {
minCompileSdk = 23
minSdk = 23
}
}
compileSdk = 33
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
testOptions {
animationsDisabled = true
unitTests.apply {
isReturnDefaultValues = true
}
}
}
It is imported to the commonMain of library A with api().
The publishing logic for library A is the same, just the name and the version is different.Császár Ákos
03/08/2024, 7:34 AMCsászár Ákos
03/08/2024, 7:43 AM