我想将我的库切换到 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... */
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
到目前为止,我明白它应该从
task<Upload>("uploadArchives") {
/* ??? */
}
Run Code Online (Sandbox Code Playgroud)
... 差不多就这样了!
AFAIU,在 Groovy 中,该Upload任务由MavenPlugin. 它在 Kotlin 中如何工作?
0.11.x(在 Gradle 4.2 中)增加了对具有约定插件的任务的更好支持以及对重型 Groovy DSL 的更好支持。完整的发行说明位于GitHub上。以下是这些注释中的相关片段:
更好地支持 Groovy-heavy DSL(#142、#47、#259)。随着 withGroovyBuilder 和实用程序扩展的引入
withConvention。withGroovyBuilder提供具有 Groovy 语义的动态调度 DSL,以便更好地与依赖 Groovy 构建器的插件(例如核心maven插件)集成。
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")
}
}
}
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1999 次 |
| 最近记录: |