我想将我的库切换为Gradle Script Kotlin,但找不到配置uploadArchive任务的方法。
这是我要翻译的普通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") {
/* ??? */
}
...就这样!
在Groovy中,AFAIU的Upload
任务是“增强”的MavenPlugin
。它在Kotlin中如何运作?
0.11.x
(在Gradle 4.2中)为具有约定插件的任务提供了更好的支持,并为重型Groovy DSL提供了更好的支持。完整的发行说明位于GitHub上。以下是这些注释中的相关片段:
对大量Groovy 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")
}
}
}
}
}
}
}
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句