Skip to content

Commit c8dd40c

Browse files
deprecate old mavenPublish extension (#340)
* deprecate old mavenPublish extension * ktlint * Update plugin/src/main/kotlin/com/vanniktech/maven/publish/MavenPublishPluginExtension.kt
1 parent 8e1f12d commit c8dd40c

File tree

4 files changed

+62
-29
lines changed

4 files changed

+62
-29
lines changed

README.md

+11-20
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ uses Gradle properties. It's generally recommended to set them in your `gradle.p
3030
file.
3131

3232
```properties
33+
SONATYPE_HOST=DEFAULT
34+
RELEASE_SIGNING_ENABLED=true
35+
3336
GROUP=com.test.mylibrary
3437
POM_ARTIFACT_ID=mylibrary-runtime
3538
VERSION_NAME=3.0.5
@@ -67,22 +70,19 @@ Without any further configuration the plugin has two tasks. `publish` which will
6770
to Maven Central (through Sonatype OSSRH) by default. To publish to the local maven repository on your
6871
machine (`~/.m2/repository`) there is `publishToMavenLocal`.
6972

70-
In case you are using `s01.oss.sonatype.org` you need to configure that like this:
71-
```groovy
72-
allprojects {
73-
plugins.withId("com.vanniktech.maven.publish") {
74-
mavenPublish {
75-
sonatypeHost = "S01"
76-
}
77-
}
78-
}
73+
In case you are using `s01.oss.sonatype.org` you need to change the `SONATYPE_HOST` property like this:
74+
```properties
75+
SONATYPE_HOST=S01
7976
```
8077

8178
The username and password for Sonatype OSS can be provided as Gradle properties called `mavenCentralUsername`
8279
and `mavenCentralPassword` to avoid having to commit them. You can also supply them as environment variables
8380
called `ORG_GRADLE_PROJECT_mavenCentralUsername` and `ORG_GRADLE_PROJECT_mavenCentralPassword`.
8481

85-
To remove the default repository set `sonatypeHost` to `null`.
82+
To remove the default repository set `SONATYPE_HOST` to an empty string.
83+
```properties
84+
SONATYPE_HOST=
85+
```
8686

8787
You can add additional repositories to publish to using the standard Gradle APIs:
8888

@@ -128,16 +128,7 @@ signingInMemoryKeyPassword=secret
128128

129129
These properties can also be provided as environment variables by prefixing them with `ORG_GRADLE_PROJECT_`
130130

131-
It is possible to disable signing of release artifacts directly in your build scripts (takes precedence):
132-
133-
```groovy
134-
mavenPublish {
135-
releaseSigningEnabled = false
136-
}
137-
```
138-
139-
Alternatively, you can use a Gradle property which is recommended if you only want to sign certain builds
140-
or only build on certain machines.
131+
It is possible to disable signing of release artifacts by adjusting your gradle.properties like this:
141132

142133
```groovy
143134
RELEASE_SIGNING_ENABLED=false

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

+3-5
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ abstract class MavenPublishBaseExtension(
1414
private val project: Project
1515
) {
1616

17-
private var mavenCentral: Pair<SonatypeHost, String?>? = null
18-
private var signing: Boolean? = null
17+
internal var mavenCentral: Pair<SonatypeHost, String?>? = null
18+
internal var signing: Boolean? = null
1919
private var pomFromProperties: Boolean? = null
2020
private var platform: Platform? = null
2121

@@ -33,9 +33,8 @@ abstract class MavenPublishBaseExtension(
3333
* @param host the instance of Sonatype OSSRH to use
3434
* @param stagingRepositoryId optional parameter to upload to a specific already created staging repository
3535
*/
36-
@Incubating
3736
@JvmOverloads
38-
fun publishToMavenCentral(host: SonatypeHost, stagingRepositoryId: String? = null) {
37+
fun publishToMavenCentral(host: SonatypeHost = SonatypeHost.DEFAULT, stagingRepositoryId: String? = null) {
3938
val mavenCentral = mavenCentral
4039
if (mavenCentral != null) {
4140
// Ignore subsequent calls with the same arguments.
@@ -102,7 +101,6 @@ abstract class MavenPublishBaseExtension(
102101
* can be found in the [Gradle documentation](https://docs.gradle.org/current/userguide/signing_plugin.html)
103102
*/
104103
// TODO update in memory set up once https://github.com/gradle/gradle/issues/16056 is implemented
105-
@Incubating
106104
fun signAllPublications() {
107105
if (signing == true) {
108106
// ignore subsequent calls with the same arguments

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

+36-2
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,45 @@ open class MavenPublishPlugin : Plugin<Project> {
2323

2424
project.afterEvaluate {
2525
val sonatypeHost = extension.sonatypeHost
26-
if (sonatypeHost != null) {
26+
// ignore old extension if new extension was already called
27+
if (sonatypeHost != null && baseExtension.mavenCentral == null) {
28+
// only print warning when sonatypeHost was not set through a gradle property, we will continue supporting this
29+
if (extension.sonatypeHostProperty() == null) {
30+
when (sonatypeHost) {
31+
SonatypeHost.DEFAULT -> project.logger.warn(
32+
"The project is currently configured to be published to " +
33+
"Maven Central. To maintain the current behavior, you need to explicitly add SONATYPE_HOST=DEFAULT to " +
34+
"your gradle.properties or add the following to your build files:\n" +
35+
"mavenPublishing {" +
36+
" publishToMavenCentral()" +
37+
"}"
38+
)
39+
SonatypeHost.S01 -> project.logger.warn(
40+
"Configuring the sonatypeHost through the DSL is deprecated. " +
41+
"Remove the old option and then add either SONATYPE_HOST=S01 to your gradle.properties or add the " +
42+
"following to your build files:\n" +
43+
"mavenPublishing {" +
44+
" publishToMavenCentral(\"S01\")" +
45+
"}"
46+
)
47+
}
48+
}
49+
2750
baseExtension.publishToMavenCentral(sonatypeHost)
2851
}
2952

30-
if (extension.releaseSigningEnabled) {
53+
// ignore old extension if new extension was already called
54+
if (extension.releaseSigningEnabled && baseExtension.signing == null) {
55+
if (extension.releaseSigningProperty() == null) {
56+
project.logger.warn(
57+
"The project is currently configured to be automatically sign release builds before " +
58+
"publishing. To maintain the current behavior you will need to explicitly add " +
59+
"RELEASE_SIGNING_ENABLED=true to your gradle.properties or add the following to your build files:\n" +
60+
"mavenPublishing {" +
61+
" signAllPublications()" +
62+
"}"
63+
)
64+
}
3165
baseExtension.signAllPublications()
3266
}
3367

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

+12-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ abstract class MavenPublishPluginExtension(
1818
*
1919
* @Since 0.15.0
2020
*/
21+
@Deprecated("Set the SONATYPE_HOST Gradle property or call mavenPublishing { publishToMavenCentral(\"<VALUE>\") } instead")
2122
var sonatypeHost: SonatypeHost? = defaultSonatypeHost()
2223

2324
/**
@@ -37,10 +38,19 @@ abstract class MavenPublishPluginExtension(
3738
*
3839
* @Since 0.9.0
3940
*/
40-
var releaseSigningEnabled: Boolean = project.findOptionalProperty("RELEASE_SIGNING_ENABLED")?.toBoolean() ?: true
41+
@Deprecated("Set the RELEASE_SIGNING_ENABLED Gradle property or call mavenPublishing { signAllPublications() } instead")
42+
var releaseSigningEnabled: Boolean = releaseSigningProperty() ?: true
43+
44+
internal fun sonatypeHostProperty(): String? {
45+
return project.findOptionalProperty("SONATYPE_HOST")
46+
}
47+
48+
internal fun releaseSigningProperty(): Boolean? {
49+
return project.findOptionalProperty("RELEASE_SIGNING_ENABLED")?.toBoolean()
50+
}
4151

4252
private fun defaultSonatypeHost(): SonatypeHost? {
43-
val property = project.findOptionalProperty("SONATYPE_HOST")
53+
val property = sonatypeHostProperty()
4454
if (property != null) {
4555
return if (property.isBlank()) {
4656
null

0 commit comments

Comments
 (0)