【问题标题】:How do you set the SoftwareComponent when publishing a Kotlin Multiplatform Library with the maven publish plugin?使用 maven 发布插件发布 Kotlin 多平台库时如何设置 SoftwareComponent?
【发布时间】:2021-12-27 21:32:58
【问题描述】:

我很难理解 Maven 发布插件如何在发布 kotlin 多平台项目时获得正确的 SoftwareComponent 发布。

在一个简单的java项目中,配置插件如下:

publishing {
    publications {
        create<MavenPublication>("maven") {
            groupId = "org.gradle.sample"
            artifactId = "library"
            version = "1.1"

            from(components["java"])
        }
    }
}

SoftwareComponent 是通过 from(components["java"]) 声明选择的。

发布kotlin multiplatform library 的教程跳过了这一点。更糟糕的是,当我将其留空并发布到本地 maven 时,我得到一个没有 jar 的空 pom.xml。

publishing {
    publications {
        register("lib", MavenPublication::class) {
         ...
        }
    }
    repositories {
         ...
    }
}

更令人困惑的是,如果我将上面的内容更改为这个,我确实得到了一个源 jar,但我没有得到所有目标平台的出版物:

publishing {
    publications {
        withType<MavenPublication> {
         ...
        }
    }
    repositories {
         ...
    }
}

上面的唯一区别是使用withType&lt;MavenPublication&gt;register("lib", MavenPublication::class)。我不确定为什么使用它们中的任何一个会产生完全不同的结果。

在使用 maven 发布插件发布 Kotlin 多平台库时如何正确设置 SoftwareComponent?

【问题讨论】:

    标签: kotlin gradle-kotlin-dsl kotlin-multiplatform maven-publish


    【解决方案1】:

    事实证明,我正确配置了maven-publish 插件以进行发布,必须注意不要覆盖 maven 发布块中的任何属性。那是

    publishing {
        publications {
            withType<MavenPublication> {
                // Don't do this. Set the group and version on the project/subproject level.
                // The multiplatform plugin will read it appropriately.
                groupId = "org.gradle.sample"
                artifactId = "library"
                version = "1.1"
            }
        }
    }
    

    按照上面的评论为我解决了问题。

    【讨论】:

      猜你喜欢
      • 2017-01-27
      • 2011-03-07
      • 2021-11-10
      • 1970-01-01
      • 1970-01-01
      • 2021-05-09
      • 2011-06-18
      • 1970-01-01
      • 2022-10-17
      相关资源
      最近更新 更多