Define uploadArchives task with gradle script kotlin

I would like to switch my libraries to Kotlin Gradle Script, but I cannot find a way to configure the uploadArchive task.

Here is the groovy kotlin Script that I would like to translate:

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... */
            }
        }
    }
}

Until now, I realized that it should start with

task<Upload>("uploadArchives") {
    /* ??? */
}

... And that is pretty much!

AFAIU, in Groovy the task is Upload"complemented" by MavenPlugin. How does it work in Kotlin?

+4
source share
1 answer

0.11.x ( Gradle 4.2) ​​ , Groovy DSL. GitHub. :

Groovy - DSL (# 142, # 47, # 259). withGroovyBuilder withConvention. withGroovyBuilder DSL Groovy , Groovy, core 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")
                }
              }
            }
          }
        }
      }
    }
  }
}
+1

Source: https://habr.com/ru/post/1654604/


All Articles