【问题标题】:Configure uploadArchives task using gradle script kotlin使用 gradle 脚本 kotlin 配置 uploadArchives 任务
【发布时间】:2016-09-14 18:10:21
【问题描述】:

我想将我的库切换到 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 中是如何工作的?

【问题讨论】:

    标签: gradle-kotlin-dsl


    【解决方案1】:

    0.11.x(在 Gradle 4.2 中)为具有 convention 插件的任务添加了更好的支持,并为重型 Groovy DSL 提供了更好的支持。完整的发行说明位于GitHub。以下是这些笔记中的相关 sn-p:

    更好地支持 Groovy-heavy DSL#142#47#259)。随着 withGroovyBuilder 和 withConvention 实用程序扩展的引入。 withGroovyBuilder 提供具有 Groovy 语义的动态调度 DSL,以便更好地与依赖于 Groovy 构建器的插件集成,例如核心 maven 插件。

    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")
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多