I'd like to switch my libraries to Gradle Script Kotlin but I can't find a way to configure the uploadArchive task.
Here's the groovy kotlin script I'd 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... */
}
}
}
}
So far, I've understood that it should start with
task<Upload>("uploadArchives") {
/* ??? */
}
... And that's pretty much it !
AFAIU, in Groovy, the Upload task is "augmented" by the MavenPlugin.
How does it work in Kotlin ?
0.11.x (in Gradle 4.2) added better support for tasks that have convention plugins and better support for heavy Groovy DSLs. The full release notes are on GitHub. Here is a relevant snippet from those notes:
Better support for Groovy-heavy DSLs (#142, #47, #259). With the introduction of the withGroovyBuilder and
withConventionutility extensions.withGroovyBuilderprovides a dynamic dispatching DSL with Groovy semantics for better integration with plugins that rely on Groovy builders such as the coremavenplugin.
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")
}
}
}
}
}
}
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With