使用Gradle Kotlin配置Maven插件

试图将项目转换为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" } } } } } 

在GSK,我得到了这么多:

 plugins.withType(MavenPlugin::class.java) { tasks.withType(Upload::class.java) { val maven = the() maven.mavenDeployer { // ??? } } } 

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

使用Gradle 4.4

mavenDeployer片通过使用Groovy动态invokeMethod调用工作,因此它不能很好地转换成kotlin-dsl

这里有一个例子展示了如何使用withGroovyBuilder方法块来配置这些特殊的Groovytypes。 您可以在0.11.1发行说明中看到有关withGroovyBuilderfunction的一些详细信息

你可能看起来像这样最新版本的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") } } }