Skip to content

Commit

Permalink
remove legacy extension (#356)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielittner committed Jun 4, 2022
1 parent f838394 commit edc9ea6
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 109 deletions.
2 changes: 2 additions & 0 deletions plugin/src/integrationTest/fixtures/common/gradle.properties
@@ -1,3 +1,5 @@
RELEASE_SIGNING_ENABLED=true

GROUP=com.example
VERSION_NAME=1.0.0
POM_ARTIFACT_ID=test-artifact
Expand Down
@@ -1,3 +1,5 @@
RELEASE_SIGNING_ENABLED=true

GROUP=com.example
VERSION_NAME=1.0.0
POM_ARTIFACT_ID=test-artifact
Expand Down
@@ -1,3 +1,5 @@
RELEASE_SIGNING_ENABLED=true

GROUP=com.example
VERSION_NAME=1.0.0
POM_ARTIFACT_ID=test-artifact
Expand Down
Expand Up @@ -14,8 +14,8 @@ abstract class MavenPublishBaseExtension(
private val project: Project
) {

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

Expand Down
Expand Up @@ -4,68 +4,25 @@ import com.vanniktech.maven.publish.legacy.configurePlatform
import com.vanniktech.maven.publish.legacy.setCoordinates
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.plugins.signing.SigningPlugin

open class MavenPublishPlugin : Plugin<Project> {

override fun apply(project: Project) {
project.plugins.apply(MavenPublishBasePlugin::class.java)
val baseExtension = project.baseExtension

// Apply signing immediately. It is also applied by `signAllPublications` but the afterEvaluate means
// that it's APIs are not available for consumers without also using afterEvaluate.
project.plugins.apply(SigningPlugin::class.java)

val extension = project.extensions.create("mavenPublish", MavenPublishPluginExtension::class.java, project)

project.setCoordinates()
project.configurePlatform()

project.afterEvaluate {
val sonatypeHost = extension.sonatypeHost
// 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)
}

// 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()
}

baseExtension.pomFromGradleProperties()
val sonatypeHost = project.findOptionalProperty("SONATYPE_HOST")
if (sonatypeHost != null && sonatypeHost.isNotBlank()) {
baseExtension.publishToMavenCentral(SonatypeHost.valueOf(sonatypeHost))
}
val releaseSigning = project.findOptionalProperty("RELEASE_SIGNING_ENABLED")?.toBoolean()
if (releaseSigning == true) {
baseExtension.signAllPublications()
}

baseExtension.pomFromGradleProperties()
}
}

This file was deleted.

Expand Up @@ -8,9 +8,6 @@ import org.gradle.plugins.signing.SigningExtension

internal fun Project.findOptionalProperty(propertyName: String) = findProperty(propertyName)?.toString()

internal inline val Project.legacyExtension: MavenPublishPluginExtension
get() = extensions.getByType(MavenPublishPluginExtension::class.java)

internal inline val Project.baseExtension: MavenPublishBaseExtension
get() = extensions.getByType(MavenPublishBaseExtension::class.java)

Expand Down

0 comments on commit edc9ea6

Please sign in to comment.