From 5a6b9496a944725b9f7a8cdbeec69705f83a4d96 Mon Sep 17 00:00:00 2001 From: Niels van Velzen Date: Sun, 17 Oct 2021 16:36:57 +0200 Subject: [PATCH] Require explicit enabling of publishing (#331) Prevents testutils (and potential future projects) from being published, also moves publishing config to AFTER the kotlin block to fix jellyfin-core-android POM and jellyfin-core Dokka --- build.gradle.kts | 22 ----------------- buildSrc/src/main/kotlin/Publishing.kt | 34 ++++++++++++++++++++++++++ jellyfin-api/build.gradle.kts | 16 ++++++------ jellyfin-core/build.gradle.kts | 17 +++++++------ jellyfin-model/build.gradle.kts | 16 ++++++------ 5 files changed, 61 insertions(+), 44 deletions(-) create mode 100644 buildSrc/src/main/kotlin/Publishing.kt diff --git a/build.gradle.kts b/build.gradle.kts index eb7d527de..6f17d31c7 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -39,31 +39,9 @@ apiValidation { subprojects { // Enable required plugins - apply() - apply() apply() apply() - // Run block after creating project specific configuration - afterEvaluate { - // Add signing config - configure { - val signingKey = getProperty("signing.key") - val signingPassword = getProperty("signing.password") ?: "" - - if (signingKey != null) { - useInMemoryPgpKeys(signingKey, signingPassword) - val publishing: PublishingExtension by project - sign(publishing.publications) - } - } - - // Add POM to projects that use publishing - configure { - publications.withType().forEach(MavenPublication::defaultPom) - } - } - // Detekt linting detekt { buildUponDefaultConfig = true diff --git a/buildSrc/src/main/kotlin/Publishing.kt b/buildSrc/src/main/kotlin/Publishing.kt new file mode 100644 index 000000000..8d0cd47ce --- /dev/null +++ b/buildSrc/src/main/kotlin/Publishing.kt @@ -0,0 +1,34 @@ +import org.gradle.api.Project +import org.gradle.api.publish.PublishingExtension +import org.gradle.api.publish.maven.MavenPublication +import org.gradle.api.publish.maven.plugins.MavenPublishPlugin +import org.gradle.kotlin.dsl.* +import org.gradle.plugins.signing.SigningExtension +import org.gradle.plugins.signing.SigningPlugin + +fun Project.enablePublishing(init: PublishingExtension.() -> Unit = {}) { + apply() + apply() + + extensions.getByType().init() + + // Run block after creating project specific configuration + afterEvaluate { + // Add signing config + configure { + val signingKey = getProperty("signing.key") + val signingPassword = getProperty("signing.password") ?: "" + + if (signingKey != null) { + useInMemoryPgpKeys(signingKey, signingPassword) + val publishing: PublishingExtension by project + sign(publishing.publications) + } + } + + // Add POM to projects that use publishing + configure { + publications.withType().forEach(MavenPublication::defaultPom) + } + } +} diff --git a/jellyfin-api/build.gradle.kts b/jellyfin-api/build.gradle.kts index d45faffc4..a92ed30f8 100644 --- a/jellyfin-api/build.gradle.kts +++ b/jellyfin-api/build.gradle.kts @@ -42,12 +42,14 @@ kotlin { } } -val javadocJar by tasks.creating(Jar::class) { - dependsOn(tasks.getByName("dokkaHtml")) - archiveClassifier.set("javadoc") - from("$buildDir/dokka/html") -} +enablePublishing { + val javadocJar by tasks.creating(Jar::class) { + dependsOn(tasks.getByName("dokkaHtml")) + archiveClassifier.set("javadoc") + from("$buildDir/dokka/html") + } -publishing.publications.withType { - artifact(javadocJar) + publications.withType { + artifact(javadocJar) + } } diff --git a/jellyfin-core/build.gradle.kts b/jellyfin-core/build.gradle.kts index 26189cd73..bb4b52e02 100644 --- a/jellyfin-core/build.gradle.kts +++ b/jellyfin-core/build.gradle.kts @@ -88,13 +88,14 @@ android { } } -val javadocJar by tasks.creating(Jar::class) { - // FIXME: Dokka is failing for this module - temporarily disabled - // dependsOn(tasks.getByName("dokkaHtml")) - archiveClassifier.set("javadoc") - // from("$buildDir/dokka/html") -} +enablePublishing { + val javadocJar by tasks.creating(Jar::class) { + dependsOn(tasks.getByName("dokkaHtml")) + archiveClassifier.set("javadoc") + from("$buildDir/dokka/html") + } -publishing.publications.withType { - artifact(javadocJar) + publications.withType { + artifact(javadocJar) + } } diff --git a/jellyfin-model/build.gradle.kts b/jellyfin-model/build.gradle.kts index 9cf7826ea..0d9e311a5 100644 --- a/jellyfin-model/build.gradle.kts +++ b/jellyfin-model/build.gradle.kts @@ -32,12 +32,14 @@ kotlin { } } -val javadocJar by tasks.creating(Jar::class) { - dependsOn(tasks.getByName("dokkaHtml")) - archiveClassifier.set("javadoc") - from("$buildDir/dokka/html") -} +enablePublishing { + val javadocJar by tasks.creating(Jar::class) { + dependsOn(tasks.getByName("dokkaHtml")) + archiveClassifier.set("javadoc") + from("$buildDir/dokka/html") + } -publishing.publications.withType { - artifact(javadocJar) + publications.withType { + artifact(javadocJar) + } }