@@ -7,10 +7,12 @@ import org.gradle.api.artifacts.Dependency
7
7
import org.gradle.api.artifacts.maven.MavenResolver
8
8
9
9
import org.gradle.api.plugins.MavenRepositoryHandlerConvention
10
+ import org.gradle.api.publication.maven.internal.deployer.MavenRemoteRepository
10
11
import org.gradle.api.tasks.Upload
11
12
import org.gradle.kotlin.dsl.*
12
13
import org.gradle.plugins.signing.Sign
13
14
import org.gradle.plugins.signing.SigningExtension
15
+ import kotlin.properties.Delegates
14
16
15
17
16
18
/* *
@@ -19,6 +21,8 @@ import org.gradle.plugins.signing.SigningExtension
19
21
*/
20
22
open class PublishedKotlinModule : Plugin <Project > {
21
23
24
+ private fun String.toBooleanOrNull () = listOf (true , false ).firstOrNull { it.toString().equals(this , ignoreCase = true ) }
25
+
22
26
override fun apply (project : Project ) {
23
27
24
28
project.run {
@@ -28,12 +32,8 @@ open class PublishedKotlinModule : Plugin<Project> {
28
32
if (! project.hasProperty(" prebuiltJar" )) {
29
33
plugins.apply (" signing" )
30
34
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
37
37
38
38
configure<SigningExtension > {
39
39
isRequired = signingRequired
@@ -95,23 +95,30 @@ open class PublishedKotlinModule : Plugin<Project> {
95
95
96
96
val username: String? by preparePublication.extra
97
97
val password: String? by preparePublication.extra
98
+ val repoUrl: String by preparePublication.extra
99
+
100
+ var repository: MavenRemoteRepository by Delegates .notNull()
98
101
99
102
repositories {
100
103
withConvention(MavenRepositoryHandlerConvention ::class ) {
101
104
102
105
mavenDeployer {
103
106
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
+ }
108
111
}
109
112
}
110
113
111
114
configurePom()
112
115
}
113
116
}
114
117
}
118
+
119
+ doFirst {
120
+ repository.url = repoUrl
121
+ }
115
122
}
116
123
117
124
val install = if (tasks.names.contains(" install" )) tasks.getByName(" install" ) as Upload
0 commit comments