Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deprecate old mavenPublish extension #340

Merged
merged 3 commits into from May 28, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 11 additions & 20 deletions README.md
Expand Up @@ -30,6 +30,9 @@ uses Gradle properties. It's generally recommended to set them in your `gradle.p
file.

```properties
SONATYPE_HOST=DEFAULT
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really don't like that you have to specify this, why can't we do default always and only if you want to change it, you have to declare it

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general there are 2 reasons for this

  • I think it's generally safer to not add something by default, this way you won't accidentally publish something internal by just running publish
  • From the plugin perspective we can avoid a lot of edge cases by having less afterEvaluate blocks, we won't be able to get rid of all of them (like when detecting which plugins are applied to the build) but at least some.

With properties we can still offer easy, low overhead configuration without the cost of afterEvaluate. If you want to publish to maven central you need to add the other properties anyways so it doesn't really increase the setup cost.

The reason for not using default as the value when no property is present is that it won't work well with the DSL. We would then call publishToMavenCentral(DEFAULT) immediately and users wouldn't be able to call publishToMavenCentral(S01) if the prefer to use the DSL over properties.

RELEASE_SIGNING_ENABLED=true
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here as above


GROUP=com.test.mylibrary
POM_ARTIFACT_ID=mylibrary-runtime
VERSION_NAME=3.0.5
Expand Down Expand Up @@ -67,22 +70,19 @@ Without any further configuration the plugin has two tasks. `publish` which will
to Maven Central (through Sonatype OSSRH) by default. To publish to the local maven repository on your
machine (`~/.m2/repository`) there is `publishToMavenLocal`.

In case you are using `s01.oss.sonatype.org` you need to configure that like this:
```groovy
allprojects {
plugins.withId("com.vanniktech.maven.publish") {
mavenPublish {
sonatypeHost = "S01"
}
}
}
In case you are using `s01.oss.sonatype.org` you need to change the `SONATYPE_HOST` property like this:
```properties
SONATYPE_HOST=S01
```

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

To remove the default repository set `sonatypeHost` to `null`.
To remove the default repository set `SONATYPE_HOST` to an empty string.
```properties
SONATYPE_HOST=
```

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

Expand Down Expand Up @@ -128,16 +128,7 @@ signingInMemoryKeyPassword=secret

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

It is possible to disable signing of release artifacts directly in your build scripts (takes precedence):

```groovy
mavenPublish {
releaseSigningEnabled = false
}
```

Alternatively, you can use a Gradle property which is recommended if you only want to sign certain builds
or only build on certain machines.
It is possible to disable signing of release artifacts by adjusting your gradle.properties like this:

```groovy
RELEASE_SIGNING_ENABLED=false
Expand Down
Expand Up @@ -14,8 +14,8 @@ abstract class MavenPublishBaseExtension(
private val project: Project
) {

private var mavenCentral: Pair<SonatypeHost, String?>? = null
private var signing: Boolean? = null
internal var mavenCentral: Pair<SonatypeHost, String?>? = null
internal var signing: Boolean? = null
private var pomFromProperties: Boolean? = null
private var platform: Platform? = null

Expand All @@ -33,9 +33,8 @@ abstract class MavenPublishBaseExtension(
* @param host the instance of Sonatype OSSRH to use
* @param stagingRepositoryId optional parameter to upload to a specific already created staging repository
*/
@Incubating
@JvmOverloads
fun publishToMavenCentral(host: SonatypeHost, stagingRepositoryId: String? = null) {
fun publishToMavenCentral(host: SonatypeHost = SonatypeHost.DEFAULT, stagingRepositoryId: String? = null) {
val mavenCentral = mavenCentral
if (mavenCentral != null) {
// Ignore subsequent calls with the same arguments.
Expand Down Expand Up @@ -102,7 +101,6 @@ abstract class MavenPublishBaseExtension(
* can be found in the [Gradle documentation](https://docs.gradle.org/current/userguide/signing_plugin.html)
*/
// TODO update in memory set up once https://github.com/gradle/gradle/issues/16056 is implemented
@Incubating
fun signAllPublications() {
if (signing == true) {
// ignore subsequent calls with the same arguments
Expand Down
Expand Up @@ -23,11 +23,45 @@ open class MavenPublishPlugin : Plugin<Project> {

project.afterEvaluate {
val sonatypeHost = extension.sonatypeHost
if (sonatypeHost != null) {
// ignore old extension if new extension was already called
if (sonatypeHost != null && baseExtension.mavenCentral == null) {
// only print warning when sonatypeHost was not set through a gradle property, we will continue supporting this
if (extension.sonatypeHostProperty() == null) {
when (sonatypeHost) {
SonatypeHost.DEFAULT -> project.logger.warn(
"The project is currently configured to be published to " +
"Maven Central. To maintain the current behavior, you need to explicitly add SONATYPE_HOST=DEFAULT to " +
"your gradle.properties or add the following to your build files:\n" +
"mavenPublishing {" +
" publishToMavenCentral()" +
"}"
)
SonatypeHost.S01 -> project.logger.warn(
"Configuring the sonatypeHost through the DSL is deprecated. " +
"Remove the old option and then add either SONATYPE_HOST=S01 to your gradle.properties or add the " +
"following to your build files:\n" +
"mavenPublishing {" +
" publishToMavenCentral(\"S01\")" +
"}"
)
}
}

baseExtension.publishToMavenCentral(sonatypeHost)
}

if (extension.releaseSigningEnabled) {
// ignore old extension if new extension was already called
if (extension.releaseSigningEnabled && baseExtension.signing == null) {
if (extension.releaseSigningProperty() == null) {
project.logger.warn(
"The project is currently configured to be automatically sign release builds before " +
"publishing. To maintain the current behavior you will need to explicitly add " +
"RELEASE_SIGNING_ENABLED=true to your gradle.properties or add the following to your build files:\n" +
"mavenPublishing {" +
" signAllPublications()" +
"}"
)
}
baseExtension.signAllPublications()
}

Expand Down
Expand Up @@ -18,6 +18,7 @@ abstract class MavenPublishPluginExtension(
*
* @Since 0.15.0
*/
@Deprecated("Set the SONATYPE_HOST Gradle property or call mavenPublishing { publishToMavenCentral(\"<VALUE>\") } instead")
var sonatypeHost: SonatypeHost? = defaultSonatypeHost()

/**
Expand All @@ -37,10 +38,19 @@ abstract class MavenPublishPluginExtension(
*
* @Since 0.9.0
*/
@Deprecated("Set the RELEASE_SIGNING_ENABLED Gradle property or call mavenPublishing { signAllPublications() } instead")
var releaseSigningEnabled: Boolean = project.findOptionalProperty("RELEASE_SIGNING_ENABLED")?.toBoolean() ?: true
gabrielittner marked this conversation as resolved.
Show resolved Hide resolved

internal fun sonatypeHostProperty(): String? {
return project.findOptionalProperty("SONATYPE_HOST")
}

internal fun releaseSigningProperty(): Boolean? {
return project.findOptionalProperty("RELEASE_SIGNING_ENABLED")?.toBoolean()
}

private fun defaultSonatypeHost(): SonatypeHost? {
val property = project.findOptionalProperty("SONATYPE_HOST")
val property = sonatypeHostProperty()
if (property != null) {
return if (property.isBlank()) {
null
Expand Down