使用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") } } }
- 如何使用gradle脚本kotlin和spring启动gradle插件来构建一个可运行的jar
- 如何用gradle-script-kotlin配置spring-boot重新打包
- 用gradle kotlin-dsl覆盖spring引导依赖版本
- 在Kotlin DSL中如何设置gradle额外属性?
- 无法使用kotlin-dsl gradle中的定制配置使用所有配置参数
- 如何在Gradle Kotlin构建中配置processResources任务
- Gradle脚本Kotlin中的锅炉项目配置
- 使用gradle脚本kotlin配置uploadArchives任务
- Gradle KTS。 如何将依赖关系配置从主构建移动到单独的文件?