Skip to content

Commit c29e44f

Browse files
ilya-gligee
authored andcommitted
Correct setup for the mavenDeployer
1 parent 4a3c828 commit c29e44f

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

buildSrc/src/main/kotlin/plugins/PublishedKotlinModule.kt

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ import org.gradle.api.artifacts.Dependency
77
import org.gradle.api.artifacts.maven.MavenResolver
88

99
import org.gradle.api.plugins.MavenRepositoryHandlerConvention
10+
import org.gradle.api.publication.maven.internal.deployer.MavenRemoteRepository
1011
import org.gradle.api.tasks.Upload
1112
import org.gradle.kotlin.dsl.*
1213
import org.gradle.plugins.signing.Sign
1314
import org.gradle.plugins.signing.SigningExtension
15+
import kotlin.properties.Delegates
1416

1517

1618
/**
@@ -19,6 +21,8 @@ import org.gradle.plugins.signing.SigningExtension
1921
*/
2022
open class PublishedKotlinModule : Plugin<Project> {
2123

24+
private fun String.toBooleanOrNull() = listOf(true, false).firstOrNull { it.toString().equals(this, ignoreCase = true) }
25+
2226
override fun apply(project: Project) {
2327

2428
project.run {
@@ -28,12 +32,8 @@ open class PublishedKotlinModule : Plugin<Project> {
2832
if (!project.hasProperty("prebuiltJar")) {
2933
plugins.apply("signing")
3034

31-
val signingProp = project.rootProject.properties["signingRequired"]
32-
val signingRequired = when (signingProp) {
33-
is Boolean -> signingProp == true
34-
is String -> listOf("true", "yes").contains(signingProp.toLowerCase().trim())
35-
else -> project.rootProject.extra["isSonatypeRelease"] as? Boolean == true
36-
}
35+
val signingRequired = project.findProperty("signingRequired")?.toString()?.toBooleanOrNull()
36+
?: project.property("isSonatypeRelease") as Boolean
3737

3838
configure<SigningExtension> {
3939
isRequired = signingRequired
@@ -95,23 +95,30 @@ open class PublishedKotlinModule : Plugin<Project> {
9595

9696
val username: String? by preparePublication.extra
9797
val password: String? by preparePublication.extra
98+
val repoUrl: String by preparePublication.extra
99+
100+
var repository: MavenRemoteRepository by Delegates.notNull()
98101

99102
repositories {
100103
withConvention(MavenRepositoryHandlerConvention::class) {
101104

102105
mavenDeployer {
103106
withGroovyBuilder {
104-
"repository"("url" to uri(preparePublication.extra["repoUrl"]))
105-
106-
if (username != null && password != null) {
107-
"authentication"("userName" to username, "password" to password)
107+
"repository"("url" to repoUrl)!!.also { repository = it as MavenRemoteRepository }.withGroovyBuilder {
108+
if (username != null && password != null) {
109+
"authentication"("userName" to username, "password" to password)
110+
}
108111
}
109112
}
110113

111114
configurePom()
112115
}
113116
}
114117
}
118+
119+
doFirst {
120+
repository.url = repoUrl
121+
}
115122
}
116123

117124
val install = if (tasks.names.contains("install")) tasks.getByName("install") as Upload

libraries/commonConfiguration.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ task preparePublication {
105105

106106
String sonatypeSnapshotsUrl = (isSonatypePublish && !isRelease) ? "https://oss.sonatype.org/content/repositories/snapshots/" : null
107107

108-
ext.repoUrl = properties["deployRepoUrl"] ?: sonatypeSnapshotsUrl ?: properties["deploy-url"] ?: "file://${rootProject.buildDir}/repo"
108+
ext.repoUrl = properties["deployRepoUrl"] ?: sonatypeSnapshotsUrl ?: properties["deploy-url"] ?: "file://${rootProject.buildDir}/repo".toString()
109109
ext.username = properties["deployRepoUsername"] ?: properties["kotlin.${repoProvider}.user"]
110110
ext.password = properties["deployRepoPassword"] ?: properties["kotlin.${repoProvider}.password"]
111111

libraries/prepareSonatypeStaging.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ preparePublication {
3030
}
3131

3232
def repoId = rootNode.data.stagedRepositoryId.text()
33-
ext.repoUrl = "http://oss.sonatype.org/service/local/staging/deployByRepositoryId/$repoId/"
33+
ext.repoUrl = "http://oss.sonatype.org/service/local/staging/deployByRepositoryId/$repoId/".toString()
3434
println "##teamcity[setParameter name='system.deploy-url' value='${repoUrl}']"
3535
}
3636
}

0 commit comments

Comments
 (0)