gradle - 使用 Gradle Kotlin 配置 Maven 插件

标签 gradle kotlin gradle-kotlin-dsl

尝试将项目转换为 GSK

我们在 Groovy 中有这个:

subprojects {
    plugins.withType(MavenPlugin) {
        tasks.withType(Upload) {
            repositories {
                mavenDeployer {
                    mavenLocal()
                    repository(url: "xxx") {
                        authentication(userName: "yyy", password: "zzz")
                    }
                    snapshotRepository(url: "xxx") {
                        authentication(userName: "yyy", password: "zzz")
                    }
                    pom.artifactId = "${project.name}"
                    pom.version = "$version"
                }
            }
        }
    }
}

在葛兰素史克,我做到了这一点:
plugins.withType(MavenPlugin::class.java) {
    tasks.withType(Upload::class.java) {
        val maven = the<MavenRepositoryHandlerConvention>()
        maven.mavenDeployer {
            // ???
        }
    }
}

我如何实际构造/配置存储库对象以分配给 MavenDeployer 的存储库/snapshotRepository 属性?
Groovy 摘录中的 mavenLocal() 对部署程序有什么作用,我如何在 Kotlin 中调用它(因为它是 RepositoryHandler 上的一个方法,而不是 MavenDeployer)?
问题,问题

使用 Gradle 4.4

最佳答案

mavenDeployer作品通过使用 Groovy 动态 invokeMethod调用所以它不能很好地转换为 kotlin-dsl .

有一个例子here显示了如何使用 withGroovyBuilder方法块来配置这些特殊的 Groovy 类型。您可以查看有关 withGroovyBuilder 的一些详细信息 0.11.1 release notes 中的功能

在最新版本的 kotlin-dsl 中,您的可能看起来像这样。 (这个例子是 0.14.x )

        withConvention(MavenRepositoryHandlerConvention::class) {

            mavenDeployer {

                withGroovyBuilder {
                    "repository"("url" to "xxx") {
                        "authentication"("userName" to "yyy", "password" to "zzz")
                    }
                    "snapshotRepository"("url" to "xxx") {
                        "authentication"("userName" to "yyy", "password" to "zzz")
                    }
                }

                pom.project {
                    withGroovyBuilder {
                        "artifactId"("${project.name}")
                        "version"("$version")
                    }
                }
            }

关于gradle - 使用 Gradle Kotlin 配置 Maven 插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48329929/

相关文章:

gradle - cxf-codegen-plugin 移植到 Gradle

kotlin - runBlocking 协程不会阻止 GlobalScope.launch (?)

android - 当新值与上一个值相同时,StateFlow 不会发出

android - Facebook SDK v4.0.1 无法使用 gradle 进行编译

android - 用于应用程序和单元测试的独立 Android Gradle Jvm 版本

gradle - 如何使用 Kotlin DSL 定义 Gradle 项目属性

gradle - 使用Kotlin DSL在Gradle构建脚本中配置swagger

gradle - 插件如何提供扩展任务?

gradle - 如何多次执行Gradle任务?

string - 为什么 Kotlin 中 null + null 的类型是隐式 String?