gpt4 book ai didi

gradle-kotlin-dsl - 使用 gradle 脚本 kotlin 配置 uploadArchives 任务

转载 作者:行者123 更新时间:2023-12-01 03:28:49 25 4
gpt4 key购买 nike

我想将我的库切换到 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“增强” .
它在 Kotlin 中是如何工作的?

最佳答案

0.11.x (在 Gradle 4.2 中)为具有约定插件的任务添加了更好的支持,并更好地支持重型 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-kotlin-dsl - 使用 gradle 脚本 kotlin 配置 uploadArchives 任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39497010/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com