5

试图将项目转换为 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 的存储库/快照存储库属性?Groovy 摘录中的 mavenLocal() 对部署者有什么作用,我如何在 Kotlin 中调用它(因为它是 RepositoryHandler 上的一个方法,而不是 MavenDeployer)?问题,问题

使用 Gradle 4.4

4

2 回答 2

3

mavenDeployer部分通过使用 Groovy 动态invokeMethod调用来工作,因此它不能很好地转换为kotlin-dsl.

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

您的最新版本可能看起来像这样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")
                    }
                }
            }
于 2018-01-19T03:57:14.463 回答
0

在你的尝试这个任务build.gradle.kts

getByName<Upload>("uploadArchives") {
    val repositoryUrl: String by project
    val repositoryUser: String by project
    val repositoryPassword: String by project
    repositories {
        withConvention(MavenRepositoryHandlerConvention::class) {
            mavenDeployer {
                withGroovyBuilder {
                    "repository"("url" to uri(repositoryUrl)) {
                        "authentication"("userName" to repositoryUser, "password" to repositoryPassword)
                    }
                }
            }
        }
    }
}

并在 yuor 中gradle.properties

repositoryUrl=${repositoryUrl}
repositoryUser=${repositoryUser}
repositoryPassword=${repositoryPassword}
于 2018-12-27T11:02:44.340 回答