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

new signing property outside of targets #101

Merged
merged 3 commits into from
Jan 31, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ mavenPublish {
snapshotRepositoryUrl = "https://oss.sonatype.org/content/repositories/snapshots/"
repositoryUsername = null // This defaults to either the SONATYPE_NEXUS_USERNAME Gradle property or the system environment variable.
repositoryPassword = null // This defaults to either the SONATYPE_NEXUS_PASSWORD Gradle property or the system environment variable.
signing = true // This defaults to true. GPG signing is required by mavenCentral. If you are deploying elsewhere, you can set this to false.
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ internal abstract class BaseMavenPublishPlugin : Plugin<Project> {

p.afterEvaluate { project ->
val configurer = when {
extension.useLegacyMode -> UploadArchivesConfigurer(project, extension.targets, ::configureMavenDeployer)
extension.useLegacyMode -> UploadArchivesConfigurer(project, ::configureMavenDeployer)
else -> MavenPublishConfigurer(project, extension.targets)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,10 @@ internal class MavenPublishConfigurer(
private fun configureSigning() {
project.signing.apply {
setRequired(project.isSigningRequired)
@Suppress("UnstableApiUsage")
sign(project.publishing.publications)
if (project.isSigningRequired.call() && project.project.publishExtension.releaseSigningEnabled) {
@Suppress("UnstableApiUsage")
sign(project.publishing.publications)
}
}
}

Expand Down Expand Up @@ -123,8 +125,7 @@ internal class MavenPublishConfigurer(
override fun configureAndroidArtifacts() {
val publication = project.publishing.publications.getByName(PUBLICATION_NAME) as MavenPublication

val extension = project.extensions.getByType(MavenPublishPluginExtension::class.java)
publication.from(project.components.getByName(extension.androidVariantToPublish))
publication.from(project.components.getByName(project.publishExtension.androidVariantToPublish))

val androidSourcesJar = project.tasks.register("androidSourcesJar", AndroidSourcesJar::class.java)
publication.addTaskOutput(androidSourcesJar)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ open class MavenPublishPluginExtension(project: Project) {

private val defaultTarget = MavenPublishTarget(
DEFAULT_TARGET,
project.findProperty("RELEASE_REPOSITORY_URL") as String? ?: System.getenv("RELEASE_REPOSITORY_URL") ?: "https://oss.sonatype.org/service/local/staging/deploy/maven2/",
project.findProperty("SNAPSHOT_REPOSITORY_URL") as String? ?: System.getenv("SNAPSHOT_REPOSITORY_URL") ?: "https://oss.sonatype.org/content/repositories/snapshots/",
project.findProperty("SONATYPE_NEXUS_USERNAME") as String? ?: System.getenv("SONATYPE_NEXUS_USERNAME"),
project.findProperty("SONATYPE_NEXUS_PASSWORD") as String? ?: System.getenv("SONATYPE_NEXUS_PASSWORD")
project.findOptionalProperty("RELEASE_REPOSITORY_URL") ?: System.getenv("RELEASE_REPOSITORY_URL") ?: "https://oss.sonatype.org/service/local/staging/deploy/maven2/",
project.findOptionalProperty("SNAPSHOT_REPOSITORY_URL") ?: System.getenv("SNAPSHOT_REPOSITORY_URL") ?: "https://oss.sonatype.org/content/repositories/snapshots/",
project.findOptionalProperty("SONATYPE_NEXUS_USERNAME") ?: System.getenv("SONATYPE_NEXUS_USERNAME"),
project.findOptionalProperty("SONATYPE_NEXUS_PASSWORD") ?: System.getenv("SONATYPE_NEXUS_PASSWORD")
)

private val localTarget = MavenPublishTarget(
Expand Down Expand Up @@ -46,6 +46,13 @@ open class MavenPublishPluginExtension(project: Project) {
*/
var androidVariantToPublish: String = "release"

/**
* Whether release artifacts should be signed before getting published.
*
* @Since 0.9.0
*/
val releaseSigningEnabled: Boolean = project.findOptionalProperty("RELEASE_SIGNING_ENABLED")?.toBoolean() ?: true

/**
* Allows to promote repositories without connecting to the nexus instance console.
* @since 0.9.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ data class MavenPublishTarget(
* Whether release artifacts should be signed before uploading to this target.
* @since 0.7.0
*/
@Deprecated("Disabling signing on a target level is not supported anymore. See releaseSigningEnabled for a replacement")
var signing: Boolean = true
) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ fun Project.findMandatoryProperty(propertyName: String): String {
}

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

val Project.publishExtension: MavenPublishPluginExtension
get() = project.extensions.getByType(MavenPublishPluginExtension::class.java)
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ import org.gradle.api.plugins.MavenPlugin
import org.gradle.api.tasks.TaskProvider
import org.gradle.api.tasks.Upload
import org.gradle.api.tasks.bundling.AbstractArchiveTask
import org.gradle.plugins.signing.Sign
import org.gradle.plugins.signing.SigningPlugin

internal class UploadArchivesConfigurer(
private val project: Project,
private val targets: Iterable<MavenPublishTarget>,
private val configureMavenDeployer: Upload.(Project, MavenPublishTarget) -> Unit
) : Configurer {

Expand All @@ -31,18 +29,9 @@ internal class UploadArchivesConfigurer(

project.signing.apply {
setRequired(project.isSigningRequired)
sign(project.configurations.getByName(ARCHIVES_CONFIGURATION))
}
project.tasks.withType(Sign::class.java).all { sign ->
sign.onlyIf {
val signedTargets = targets.filter { it.signing }
sign.logger.info("Targets that should be signed: ${signedTargets.map { it.name }}")
signedTargets.any { target ->
val task = project.tasks.getByName(target.taskName)
project.gradle.taskGraph.hasTask(task).also {
sign.logger.info("Task for ${target.name} will be executed: $it")
}
}

if (project.isSigningRequired.call() && project.publishExtension.releaseSigningEnabled) {
sign(project.configurations.getByName(ARCHIVES_CONFIGURATION))
}
}
}
Expand Down