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
This commit is contained in:
Niels van Velzen 2021-10-17 16:36:57 +02:00 committed by GitHub
parent a5780c4e8d
commit 5a6b9496a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 61 additions and 44 deletions

View File

@ -39,31 +39,9 @@ apiValidation {
subprojects {
// Enable required plugins
apply<SigningPlugin>()
apply<MavenPublishPlugin>()
apply<io.gitlab.arturbosch.detekt.DetektPlugin>()
apply<org.jetbrains.dokka.gradle.DokkaPlugin>()
// Run block after creating project specific configuration
afterEvaluate {
// Add signing config
configure<SigningExtension> {
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<PublishingExtension> {
publications.withType<MavenPublication>().forEach(MavenPublication::defaultPom)
}
}
// Detekt linting
detekt {
buildUponDefaultConfig = true

View File

@ -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<SigningPlugin>()
apply<MavenPublishPlugin>()
extensions.getByType<PublishingExtension>().init()
// Run block after creating project specific configuration
afterEvaluate {
// Add signing config
configure<SigningExtension> {
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<PublishingExtension> {
publications.withType<MavenPublication>().forEach(MavenPublication::defaultPom)
}
}
}

View File

@ -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<MavenPublication> {
artifact(javadocJar)
publications.withType<MavenPublication> {
artifact(javadocJar)
}
}

View File

@ -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<MavenPublication> {
artifact(javadocJar)
publications.withType<MavenPublication> {
artifact(javadocJar)
}
}

View File

@ -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<MavenPublication> {
artifact(javadocJar)
publications.withType<MavenPublication> {
artifact(javadocJar)
}
}