简体   繁体   English

gradle maven 使用 kotlin-dsl 发布 Pom

[英]gradle maven publish Pom using kotlin-dsl

I have a multiplatform kotlin library project that publishes to maven and have been updating to the kotlin 1.3 multiplatform model and kotlin-dsl我有一个发布到 maven 的多平台 kotlin 库项目,并且一直在更新到 kotlin 1.3 多平台模型和 kotlin-dsl

The previous groovy gradle script has a modifyPom block, and i found an example here .之前的 groovy gradle 脚本有一个 modifyPom 块,我在这里找到了一个例子 However as soon as I add但是,一旦我添加

val modifyPom : Closure<*> by ext

modifyPom(closureOf<MavenPom> {
   // pom code in here
})

I get the same result no matter what is in the pom data, which is that the call of the modifyPom groovy closure breaks the build with a very vague error:无论 pom 数据中有什么,我都会得到相同的结果,即 modifyPom groovy 闭包的调用以非常模糊的错误破坏了构建:

Build file '<path>\build.gradle.kts' line: 47
Open File

In other words the line number of the call of modifyPom groovy Closure, but nothing about the actual error.换句话说,调用 modifyPom groovy Closure 的行号,但与实际错误无关。

I am using Gradle 5.0.我正在使用 Gradle 5.0。 Any help appreciated.任何帮助表示赞赏。

So - in Groovy I had this block for configuring POMs, and it worked just fine:所以 - 在 Groovy 中,我有这个用于配置 POM 的块,它工作得很好:

    project.publishing.publications.forEach { publication ->
        publication.pom.withXml {
            def root = asNode()
            root.appendNode("name", "libui")
            root.appendNode("description", "Kotlin/Native interop to libui: a portable GUI library")
            root.appendNode("url", POM_SCM_URL)
            root.children().last() + {
                licenses {
                    license {
                        name "MIT License"
                        url POM_SCM_URL
                        distribution "repo"
                    }
                }
                developers {
                    developer {
                        id "msink"
                        name "Mike Sinkovsky"
                        email "msink@permonline.ru"
                    }
                }
                scm {
                    url POM_SCM_URL
                    connection POM_SCM_CONNECTION
                    developerConnection POM_SCM_DEV_CONNECTION
                }
            }
        }
    }

And how to convert it to Kotlin DSL?以及如何将其转换为 Kotlin DSL?

Edit: Well, was answered in https://github.com/JetBrains/kotlin-native/issues/2372 In Gradle Kotlin DSL it becomes:编辑:嗯,在https://github.com/JetBrains/kotlin-native/issues/2372中回答了在 Gradle Kotlin DSL 中它变成:

project.publishing.publications.withType<MavenPublication>().forEach { publication ->
    with(publication.pom) {
        withXml {
            val root = asNode()
            root.appendNode("name", "libui")
            root.appendNode("description", "Kotlin/Native interop to libui: a portable GUI library")
            root.appendNode("url", POM_SCM_URL)
        }

        licenses {
            license {
                name.set("MIT License")
                url.set(POM_SCM_URL)
                distribution.set("repo")
            }
        }
        developers {
            developer {
                id.set("msink")
                name.set("Mike Sinkovsky")
                email.set("msink@permonline.ru")
            }
        }
        scm {
            url.set(POM_SCM_URL)
            connection.set(POM_SCM_CONNECTION)
            developerConnection.set(POM_SCM_DEV_CONNECTION)
        }
    }
}

This problem was fixed by changing the definition of modifyPom to通过将 modifyPom 的定义更改为

val modifyPom : Closure<MavenPom> by ext

That fixed the original problem as posted, and the pom is now being modified.这修复了发布的原始问题,现在正在修改 pom。 If anyone needs help, add a comment and hopefully I will notice如果有人需要帮助,请添加评论,希望我会注意到

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM