嘿,我正在 kotlin 多平台上发布库。我用这个命令
./gradlew clean assemble publish
我的三个包就生成了。我给出了这个名字 var libraryArtifactId = "kmm-module"
但我不明白为什么会有其他名字。
第一个包名称是
com.vivek.kmm-module
第二个包名称是
com.vivek.kotlinproject-android-debug
第三个包名称是
com.vivek.kotlinproject-android
我理解第一个包名称,但我不理解第二个和第三个 artificatId 来自哪里?
build.gradle.kts
plugins {
kotlin("multiplatform") version "1.6.21"
id("com.android.library")
id("maven-publish")
}
val libraryVersion = "0.0.1"
var libraryGroup = "com.vivek"
var libraryArtifactId = "kmm-module"
repositories {
google()
mavenCentral()
}
kotlin {
android {
publishLibraryVariants("release", "debug")
}
sourceSets {
val commonMain by getting
val androidMain by getting
}
}
android {
compileSdk = 21
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
defaultConfig {
minSdk = 21
targetSdk = 31
}
@Suppress("UnstableApiUsage") compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
}
publishing {
publications {
group = libraryGroup
publications.withType<MavenPublication> {
groupId = libraryGroup
artifactId = libraryArtifactId
version = libraryVersion
}
repositories {
maven {
url = uri("https://maven.pkg.github.com/vivek-modi/kotlinmultiplatfromproject")
credentials {
username = (System.getenv("GITHUB_USER") ?: project.properties["GITHUB_USER"]).toString()
password = (System.getenv("GITHUB_PERSONAL_ACCESS_TOKEN") ?: project.properties["GITHUB_PERSONAL_ACCESS_TOKEN"]).toString()
}
}
}
}
}
我正在添加我的 github 存储库。我使用 github 包来发布库。谢谢
我很惊讶这并不容易。这终于对我有用了:
afterEvaluate {
configure<PublishingExtension> {
publications.all {
val mavenPublication = this as? MavenPublication
// rename artifactId from default one
if (mavenPublication?.artifactId == "shared-android") {
mavenPublication.artifactId = "custom-artifact-id"
}
}
}
您可以删除此行以避免 android 工件。
android {
publishLibraryVariants("release", "debug")
}