使用 gradle 脚本 kotlin 配置 uploadArchives 任务
Configure uploadArchives task using gradle script kotlin
我想将我的库切换到 Gradle Script Kotlin,但我找不到配置 uploadArchive 任务的方法。
这是我要翻译的 groovy kotlin 脚本:
uploadArchives {
repositories {
mavenDeployer {
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
pom.project {
/* A lot of stuff... */
}
}
}
}
到目前为止,我明白它应该以
开头
task<Upload>("uploadArchives") {
/* ??? */
}
...差不多就是这些了!
AFAIU,在 Groovy 中,Upload
任务是由 MavenPlugin
完成的 "augmented"。
它在 Kotlin 中是如何工作的?
0.11.x
(在 Gradle 4.2 中)添加了对具有 convention 插件的任务的更好支持,以及对重 Groovy DSL 的更好支持。完整的发行说明在 GitHub 上。以下是这些笔记中的相关片段:
Better support for Groovy-heavy DSLs (#142, #47, #259). With the introduction of the withGroovyBuilder and withConvention
utility extensions. withGroovyBuilder
provides a dynamic dispatching DSL with Groovy semantics for better integration with plugins that rely on Groovy builders such as the core maven
plugin.
Here is an example taken directly from the source code:
plugins {
java
maven
}
group = "org.gradle.kotlin-dsl"
version = "1.0"
tasks {
"uploadArchives"(Upload::class) {
repositories {
withConvention(MavenRepositoryHandlerConvention::class) {
mavenDeployer {
withGroovyBuilder {
"repository"("url" to uri("$buildDir/m2/releases"))
"snapshotRepository"("url" to uri("$buildDir/m2/snapshots"))
}
pom.project {
withGroovyBuilder {
"parent" {
"groupId"("org.gradle")
"artifactId"("kotlin-dsl")
"version"("1.0")
}
"licenses" {
"license" {
"name"("The Apache Software License, Version 2.0")
"url"("http://www.apache.org/licenses/LICENSE-2.0.txt")
"distribution"("repo")
}
}
}
}
}
}
}
}
}
我想将我的库切换到 Gradle Script Kotlin,但我找不到配置 uploadArchive 任务的方法。
这是我要翻译的 groovy kotlin 脚本:
uploadArchives {
repositories {
mavenDeployer {
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
pom.project {
/* A lot of stuff... */
}
}
}
}
到目前为止,我明白它应该以
开头task<Upload>("uploadArchives") {
/* ??? */
}
...差不多就是这些了!
AFAIU,在 Groovy 中,Upload
任务是由 MavenPlugin
完成的 "augmented"。
它在 Kotlin 中是如何工作的?
0.11.x
(在 Gradle 4.2 中)添加了对具有 convention 插件的任务的更好支持,以及对重 Groovy DSL 的更好支持。完整的发行说明在 GitHub 上。以下是这些笔记中的相关片段:
Better support for Groovy-heavy DSLs (#142, #47, #259). With the introduction of the withGroovyBuilder and
withConvention
utility extensions.withGroovyBuilder
provides a dynamic dispatching DSL with Groovy semantics for better integration with plugins that rely on Groovy builders such as the coremaven
plugin.
Here is an example taken directly from the source code:
plugins {
java
maven
}
group = "org.gradle.kotlin-dsl"
version = "1.0"
tasks {
"uploadArchives"(Upload::class) {
repositories {
withConvention(MavenRepositoryHandlerConvention::class) {
mavenDeployer {
withGroovyBuilder {
"repository"("url" to uri("$buildDir/m2/releases"))
"snapshotRepository"("url" to uri("$buildDir/m2/snapshots"))
}
pom.project {
withGroovyBuilder {
"parent" {
"groupId"("org.gradle")
"artifactId"("kotlin-dsl")
"version"("1.0")
}
"licenses" {
"license" {
"name"("The Apache Software License, Version 2.0")
"url"("http://www.apache.org/licenses/LICENSE-2.0.txt")
"distribution"("repo")
}
}
}
}
}
}
}
}
}