Skip to content

Commit f041faa

Browse files
authored
Open up SonatypeHost (#504)
fixes #503
1 parent 9300a2b commit f041faa

2 files changed

Lines changed: 24 additions & 5 deletions

File tree

plugin/src/main/kotlin/com/vanniktech/maven/publish/MavenPublishBaseExtension.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ abstract class MavenPublishBaseExtension(
8080
project.tasks.registerDropRepository(buildService)
8181
}
8282

83+
@JvmOverloads
84+
@JvmSynthetic
85+
fun publishToMavenCentral(host: String, automaticRelease: Boolean = false) {
86+
publishToMavenCentral(SonatypeHost.valueOf(host), automaticRelease)
87+
}
88+
8389
/**
8490
* Automatically apply Gradle's `signing` plugin and configure all publications to be signed. If signing credentials
8591
* are not configured this will fail the build unless the current version is a `SNAPSHOT`.

plugin/src/main/kotlin/com/vanniktech/maven/publish/SonatypeHost.kt

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.vanniktech.maven.publish
22

3+
import java.io.Serializable
34
import org.gradle.api.provider.Provider
45

56
/**
@@ -8,12 +9,9 @@ import org.gradle.api.provider.Provider
89
*
910
* https://central.sonatype.org/articles/2021/Feb/23/new-users-on-s01osssonatypeorg/
1011
*/
11-
enum class SonatypeHost(
12+
data class SonatypeHost(
1213
internal val rootUrl: String
13-
) {
14-
DEFAULT("https://oss.sonatype.org"),
15-
S01("https://s01.oss.sonatype.org");
16-
14+
) : Serializable {
1715
internal fun apiBaseUrl(): String {
1816
return "$rootUrl/service/local/"
1917
}
@@ -28,4 +26,19 @@ enum class SonatypeHost(
2826
"$rootUrl/service/local/staging/deployByRepositoryId/${stagingRepositoryId.get()}/"
2927
}
3028
}
29+
30+
companion object {
31+
@JvmStatic
32+
fun valueOf(sonatypeHost: String): SonatypeHost = when (sonatypeHost) {
33+
"DEFAULT" -> DEFAULT
34+
"S01" -> S01
35+
else -> throw IllegalArgumentException("No SonatypeHost constant $sonatypeHost")
36+
}
37+
38+
@JvmField
39+
val DEFAULT = SonatypeHost("https://oss.sonatype.org")
40+
41+
@JvmField
42+
val S01 = SonatypeHost("https://s01.oss.sonatype.org")
43+
}
3144
}

0 commit comments

Comments
 (0)