尝试将项目转换为 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/