Correct setup for the mavenDeployer
This commit is contained in:
committed by
Ilya Chernikov
parent
4a3c8286a3
commit
c29e44f057
@@ -7,10 +7,12 @@ import org.gradle.api.artifacts.Dependency
|
||||
import org.gradle.api.artifacts.maven.MavenResolver
|
||||
|
||||
import org.gradle.api.plugins.MavenRepositoryHandlerConvention
|
||||
import org.gradle.api.publication.maven.internal.deployer.MavenRemoteRepository
|
||||
import org.gradle.api.tasks.Upload
|
||||
import org.gradle.kotlin.dsl.*
|
||||
import org.gradle.plugins.signing.Sign
|
||||
import org.gradle.plugins.signing.SigningExtension
|
||||
import kotlin.properties.Delegates
|
||||
|
||||
|
||||
/**
|
||||
@@ -19,6 +21,8 @@ import org.gradle.plugins.signing.SigningExtension
|
||||
*/
|
||||
open class PublishedKotlinModule : Plugin<Project> {
|
||||
|
||||
private fun String.toBooleanOrNull() = listOf(true, false).firstOrNull { it.toString().equals(this, ignoreCase = true) }
|
||||
|
||||
override fun apply(project: Project) {
|
||||
|
||||
project.run {
|
||||
@@ -28,12 +32,8 @@ open class PublishedKotlinModule : Plugin<Project> {
|
||||
if (!project.hasProperty("prebuiltJar")) {
|
||||
plugins.apply("signing")
|
||||
|
||||
val signingProp = project.rootProject.properties["signingRequired"]
|
||||
val signingRequired = when (signingProp) {
|
||||
is Boolean -> signingProp == true
|
||||
is String -> listOf("true", "yes").contains(signingProp.toLowerCase().trim())
|
||||
else -> project.rootProject.extra["isSonatypeRelease"] as? Boolean == true
|
||||
}
|
||||
val signingRequired = project.findProperty("signingRequired")?.toString()?.toBooleanOrNull()
|
||||
?: project.property("isSonatypeRelease") as Boolean
|
||||
|
||||
configure<SigningExtension> {
|
||||
isRequired = signingRequired
|
||||
@@ -95,16 +95,19 @@ open class PublishedKotlinModule : Plugin<Project> {
|
||||
|
||||
val username: String? by preparePublication.extra
|
||||
val password: String? by preparePublication.extra
|
||||
val repoUrl: String by preparePublication.extra
|
||||
|
||||
var repository: MavenRemoteRepository by Delegates.notNull()
|
||||
|
||||
repositories {
|
||||
withConvention(MavenRepositoryHandlerConvention::class) {
|
||||
|
||||
mavenDeployer {
|
||||
withGroovyBuilder {
|
||||
"repository"("url" to uri(preparePublication.extra["repoUrl"]))
|
||||
|
||||
if (username != null && password != null) {
|
||||
"authentication"("userName" to username, "password" to password)
|
||||
"repository"("url" to repoUrl)!!.also { repository = it as MavenRemoteRepository }.withGroovyBuilder {
|
||||
if (username != null && password != null) {
|
||||
"authentication"("userName" to username, "password" to password)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,6 +115,10 @@ open class PublishedKotlinModule : Plugin<Project> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
doFirst {
|
||||
repository.url = repoUrl
|
||||
}
|
||||
}
|
||||
|
||||
val install = if (tasks.names.contains("install")) tasks.getByName("install") as Upload
|
||||
|
||||
@@ -105,7 +105,7 @@ task preparePublication {
|
||||
|
||||
String sonatypeSnapshotsUrl = (isSonatypePublish && !isRelease) ? "https://oss.sonatype.org/content/repositories/snapshots/" : null
|
||||
|
||||
ext.repoUrl = properties["deployRepoUrl"] ?: sonatypeSnapshotsUrl ?: properties["deploy-url"] ?: "file://${rootProject.buildDir}/repo"
|
||||
ext.repoUrl = properties["deployRepoUrl"] ?: sonatypeSnapshotsUrl ?: properties["deploy-url"] ?: "file://${rootProject.buildDir}/repo".toString()
|
||||
ext.username = properties["deployRepoUsername"] ?: properties["kotlin.${repoProvider}.user"]
|
||||
ext.password = properties["deployRepoPassword"] ?: properties["kotlin.${repoProvider}.password"]
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ preparePublication {
|
||||
}
|
||||
|
||||
def repoId = rootNode.data.stagedRepositoryId.text()
|
||||
ext.repoUrl = "http://oss.sonatype.org/service/local/staging/deployByRepositoryId/$repoId/"
|
||||
ext.repoUrl = "http://oss.sonatype.org/service/local/staging/deployByRepositoryId/$repoId/".toString()
|
||||
println "##teamcity[setParameter name='system.deploy-url' value='${repoUrl}']"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user