发布Kotlin多平台库Bintray使用Kotlin DSL

问题描述 投票:1回答:1

我用Kotlin MultiPlatform(link)编写了一个库我可以将库作为jar文件添加到项目中但是现在我想用bintray

做到这一点

我继续使用Link,但是有问题

我的[[问题是我给Gradle的publicationName变量的值对我来说是错误的:

val publicationName = "MySharedCode" publishing { publications.invoke { publicationName(MavenPublication::class) { artifactId = artifactID artifact(shadowJar) pom.addDependencies() } } } Gradle Sync Error : Publication with name 'MySharedCode' not found.
[我的Kotlin Gradle DSL文件:

import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar import com.jfrog.bintray.gradle.BintrayExtension import org.gradle.api.publish.maven.MavenPom import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { kotlin("multiplatform") `maven-publish` id("com.jfrog.bintray") version "1.8.4" id ("com.github.johnrengelman.shadow") version "5.2.0" java } val ktorVersion = "1.3.0-rc2" val serialization = "0.11.0" val coroutines = "1.2.1" project.group = "com.my.domain" project.version = "0.0.3" val artifactID = "my-shared-lib" kotlin { //select iOS target platform depending on the Xcode environment variables val iOSTarget: (String, KotlinNativeTarget.() -> Unit) -> KotlinNativeTarget = if (System.getenv("SDK_NAME")?.startsWith("iphoneos") == true) ::iosArm64 else ::iosX64 iOSTarget("ios") { binaries { framework { baseName = "MySharedCode" } } } jvm("android") sourceSets["commonMain"].dependencies { implementation("org.jetbrains.kotlin:kotlin-stdlib-common") // HTTP implementation("io.ktor:ktor-client-core:$ktorVersion") implementation("io.ktor:ktor-client-json:$ktorVersion") implementation("io.ktor:ktor-client-serialization:$ktorVersion") // Coroutines implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$coroutines") } sourceSets["androidMain"].dependencies { implementation("org.jetbrains.kotlin:kotlin-stdlib") // HTTP implementation("io.ktor:ktor-client-android:$ktorVersion") implementation("io.ktor:ktor-client-json-jvm:$ktorVersion") implementation("io.ktor:ktor-client-serialization-jvm:$ktorVersion") // Coroutines implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines") } sourceSets["iosMain"].dependencies { implementation("org.jetbrains.kotlin:kotlin-stdlib") // HTTP implementation("io.ktor:ktor-client-ios:$ktorVersion") implementation("io.ktor:ktor-client-json-native:$ktorVersion") implementation("io.ktor:ktor-client-serialization-iosx64:$ktorVersion") // Coroutines implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-native:$coroutines") } } val packForXcode by tasks.creating(Sync::class) { group = "build" val mode = System.getenv("CONFIGURATION") ?: "DEBUG" val framework = kotlin.targets.getByName<KotlinNativeTarget>("ios").binaries.getFramework(mode) inputs.property("mode", mode) dependsOn(framework.linkTask) val targetDir = File(buildDir, "xcode-frameworks") from({ framework.outputDirectory }) into(targetDir) doLast { val gradlew = File(targetDir, "gradlew") gradlew.writeText("#!/bin/bash\nexport 'JAVA_HOME=${System.getProperty("java.home")}'\ncd '${rootProject.rootDir}'\n./gradlew \$@\n") gradlew.setExecutable(true) } } tasks.getByName("build").dependsOn(packForXcode) val shadowJar: ShadowJar by tasks shadowJar.apply { baseName = artifactID classifier = null } fun MavenPom.addDependencies() = withXml { asNode().appendNode("dependencies").let { depNode -> configurations.commonMainImplementation.allDependencies.forEach { depNode.appendNode("dependency").apply { appendNode("groupId", it.group) appendNode("artifactId", it.name) appendNode("version", it.version) } } } } val publicationName = "MySharedCode" publishing { publications.invoke { publicationName(MavenPublication::class) { artifactId = artifactID artifact(shadowJar) pom.addDependencies() } } } fun findProperty(s: String) = project.findProperty(s) as String? bintray { user = "xxxx" key = "xxxx" publish = true setPublications(publicationName) pkg(delegateClosureOf<BintrayExtension.PackageConfig> { repo = "lib" name = "my repo name" userOrg = "my user org" websiteUrl = "https://my-domain.com/" githubRepo = "myRepo" vcsUrl = "myRepo url" description = "my repo description" setLabels("kotlin") setLicenses("MIT") desc = description }) } tasks { withType(GradleBuild::class.java) { dependsOn(shadowJar) } withType<KotlinCompile> { kotlinOptions.jvmTarget = "1.8" } withType(Test::class.java) { testLogging.showStandardStreams = true } withType<GenerateMavenPom> { destination = file("$buildDir/libs/${shadowJar.name}.pom") } }

android gradle gradle-kotlin-dsl bintray kotlin-multiplatform
1个回答
0
投票
这是我第一次看到Kotlin DSL中的“纸盒”。但是根据他们的文档
© www.soinside.com 2019 - 2024. All rights reserved.