Kotlin Multiplatform与Dokka和来源发布
我正在努力将Kotlin乘法项目正确发布给Maven(现在是Mavenlocal)。我可以将依赖关系添加到另一个多平台项目并使用代码,但是我没有任何文档,我不确定我是否做错了什么,或者目前根本无法做到这一点。
据我了解,您不能使用普通的Javadoc,因为它义务与Java无意义,这在乘法环境中是没有意义的。我在某个地方读到,在这种情况下,您应该使用Dokka的HTML版本。我可以看到我得到了一个“ javadoc.jar”,其中包含我的mvenlocal的内容,但仍在IDE中,在一个示例项目中,我将KMP库添加为依赖关系,我看不到任何文档。 另外,代码分解似乎很奇怪。我猜这些来源也无法正确解决。
根据文档,只需添加Maven-Publish和Dokka插件,一切都应该自动并完美地工作。但是似乎不是这样,实际上没有什么能正如我期望的那样奏效的:D
有人知道,如何正确设置它?
我的gradle文件看起来像这样:
plugins {
kotlin("multiplatform") version "1.6.21"
id("org.jetbrains.kotlinx.benchmark") version "0.4.2"
id("org.jetbrains.dokka") version "1.6.21"
`maven-publish`
signing
}
group = "io.github.quillraven.fleks"
version = "1.4-KMP-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_1_8
repositories {
mavenCentral()
}
kotlin {
targets {
jvm {
compilations {
all {
kotlinOptions {
jvmTarget = "1.8"
}
}
val main by getting { }
// custom benchmark compilation
val benchmarks by compilations.creating {
defaultSourceSet {
dependencies {
// Compile against the main compilation's compile classpath and outputs:
implementation(main.compileDependencyFiles + main.output.classesDirs)
}
}
}
}
withJava()
testRuns["test"].executionTask.configure {
useJUnitPlatform()
}
}
}
js(BOTH) {
browser { }
}
val hostOs = System.getProperty("os.name")
val isMingwX64 = hostOs.startsWith("Windows")
val nativeTarget = when {
hostOs == "Mac OS X" -> macosX64("native")
hostOs == "Linux" -> linuxX64("native")
isMingwX64 -> mingwX64("native")
else -> throw GradleException("Host OS is not supported in Kotlin/Native.")
}
sourceSets {
val commonMain by getting { }
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
}
}
val jvmMain by getting
val jvmTest by getting
val jvmBenchmarks by getting {
dependsOn(commonMain)
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-benchmark-runtime:0.4.2")
implementation("com.badlogicgames.ashley:ashley:1.7.4")
implementation("net.onedaybeard.artemis:artemis-odb:2.3.0")
}
}
val jsMain by getting
val jsTest by getting
val nativeMain by getting
val nativeTest by getting
}
}
benchmark {
targets {
register("jvmBenchmarks")
}
}
val javadocJar by tasks.registering(Jar::class) {
archiveClassifier.set("javadoc")
from(tasks.dokkaHtml)
}
publishing {
repositories {
maven {
url = if (project.version.toString().endsWith("SNAPSHOT")) {
uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
} else {
uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/")
}
credentials {
username = System.getenv("OSSRH_USERNAME")
password = System.getenv("OSSRH_TOKEN")
}
}
}
publications {
val kotlinMultiplatform by getting(MavenPublication::class) {
version = project.version.toString()
groupId = project.group.toString()
artifactId = "Fleks"
artifact(javadocJar)
pom {
name.set("Fleks")
description.set("A lightweight entity component system written in Kotlin.")
url.set("https://github.com/Quillraven/Fleks")
scm {
connection.set("scm:git:[email protected]:quillraven/fleks.git")
developerConnection.set("scm:git:[email protected]:quillraven/fleks.git")
url.set("https://github.com/quillraven/fleks/")
}
licenses {
license {
name.set("MIT License")
url.set("https://opensource.org/licenses/MIT")
}
}
developers {
developer {
id.set("Quillraven")
name.set("Simon Klausner")
email.set("[email protected]")
}
}
}
}
signing {
useInMemoryPgpKeys(System.getenv("SIGNING_KEY"), System.getenv("SIGNING_PASSWORD"))
sign(kotlinMultiplatform)
}
}
}
// only sign if version is not a SNAPSHOT release.
// this makes it easier to publish to mavenLocal and test the packed version.
tasks.withType<Sign>().configureEach {
onlyIf { !project.version.toString().endsWith("SNAPSHOT") }
}
当我运行 PublishTomavenLocal
gradle任务时,我在.m2文件夹中获取关注目录:
然后创建一个示例项目并将其添加为依赖关系时,我看不到任何快速文档,并且分解编译无法正常工作:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是我的示例Gradle文件,它将带有源和Javadocs的Kotlin多平台项目发布到Maven存储库。
项目来源在这里:
Here is my example gradle file that publishes a kotlin multiplatform project with sources and javadocs to a maven repository.
The project source is here: https://github.com/danbrough/misc_demos/tree/master/kotlin_multiplatform_dokka
我终于能够发布到Mavencentral。不确定这是否是最好的方法和正确的方法,但似乎有效。这是我的build.gradle.kts。重要的部分是出版物部分。无论出于何种原因,都不足以正确设置“根”文件夹。我还必须调整每个出版物的POM,Javadoc和签名。
I was finally able to publish to mavenCentral. Not sure if this is the best way and correct way to do it, but it seems to work. Here is my build.gradle.kts. The important part is in the publications sections. For whatever reason it is not sufficient to have the "root" folder setup properly. I also had to adjust the pom, javadoc and signing of every single publication, too.