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

remove legacy extension #356

Merged
merged 1 commit into from Jun 4, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
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