使用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
发行说明中看到有关withGroovyBuilder
function的一些详细信息
你可能看起来像这样最新版本的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") } } }
- 转换Android项目使用Gradle脚本Kotlin
- 在gradle-kotlin-dsl中的Android产品Flavors
- 我怎样才能用Kotlin DSL为Gradle配置Kotlin协程?
- 不同的方式来应用插件? (Gradle Kotlin DSL)
- 如何在Gradle Kotlin构建中配置processResources任务
- 如何将ext。*变量转换为build.gradle.kts中的插件块
- 找不到Kotlin脚本Gradle的kotlin-gradle-plugin
- 如何用gradle kotlin-dsl添加新的源代码集
- 如何用gradle-script-kotlin配置spring-boot重新打包