|
| 1 | +/* |
| 2 | + * Copyright (c) 2026 dexpace and Omar Aljarrah |
| 3 | + * |
| 4 | + * Licensed under the MIT License. See LICENSE in the project root. |
| 5 | + * SPDX-License-Identifier: MIT |
| 6 | + */ |
| 7 | + |
| 8 | +// Convention plugin for every module that is published to Maven Central. It carries the |
| 9 | +// `maven-publish` + `signing` setup, the shared POM metadata, the staging repository, and the |
| 10 | +// CI-gated signing configuration that was previously copied verbatim into all nine module |
| 11 | +// build scripts. |
| 12 | +// |
| 13 | +// A module opts in with `plugins { id("dexpace.published-module") }`. The publication name, |
| 14 | +// coordinates, POM, repository, and signing behaviour are then identical across modules; the |
| 15 | +// `name`/`description` fields derive from `project.name`, so a module needs no further |
| 16 | +// publishing configuration. A module that must NOT be published simply does not apply this |
| 17 | +// plugin. |
| 18 | + |
| 19 | +plugins { |
| 20 | + `maven-publish` |
| 21 | + signing |
| 22 | +} |
| 23 | + |
| 24 | +// Coordinates (`group`/`version`) are not set here. Gradle applies them from the repository-root |
| 25 | +// `gradle.properties` to the root project and every subproject, so each consuming module already |
| 26 | +// carries the shared `org.dexpace` coordinates and current version by the time this plugin runs — |
| 27 | +// a coordinate bump is a one-line edit in that file. |
| 28 | + |
| 29 | +// The `library` publication is built from the `java` software component, which only exists once a |
| 30 | +// `java`/`java-library`/`kotlin("jvm")` plugin is applied. Every current consumer applies |
| 31 | +// `kotlin("jvm")`, but this plugin neither applies nor requires one, so the whole publication + |
| 32 | +// signing setup is guarded on the Kotlin JVM plugin. Without the guard, a module that opted in |
| 33 | +// without a Java/Kotlin plugin would fail with an opaque "SoftwareComponent with name java not |
| 34 | +// found". |
| 35 | +pluginManager.withPlugin("org.jetbrains.kotlin.jvm") { |
| 36 | + publishing { |
| 37 | + publications { |
| 38 | + create<MavenPublication>("library") { |
| 39 | + from(components["java"]) |
| 40 | + pom { |
| 41 | + name.set(project.name) |
| 42 | + description.set("Dexpace Java SDK — ${project.name}") |
| 43 | + url.set("https://github.com/dexpace/java-sdk") |
| 44 | + licenses { |
| 45 | + license { |
| 46 | + name.set("MIT License") |
| 47 | + url.set("https://github.com/dexpace/java-sdk/blob/main/LICENSE") |
| 48 | + distribution.set("repo") |
| 49 | + } |
| 50 | + } |
| 51 | + developers { |
| 52 | + developer { |
| 53 | + id.set("dexpace") |
| 54 | + name.set("Dexpace SDK Team") |
| 55 | + } |
| 56 | + } |
| 57 | + scm { |
| 58 | + connection.set("scm:git:https://github.com/dexpace/java-sdk.git") |
| 59 | + developerConnection.set("scm:git:ssh://github.com/dexpace/java-sdk.git") |
| 60 | + url.set("https://github.com/dexpace/java-sdk") |
| 61 | + } |
| 62 | + } |
| 63 | + } |
| 64 | + } |
| 65 | + repositories { |
| 66 | + // Local staging repository. CI must override this to publish to a real remote. |
| 67 | + maven { |
| 68 | + name = "local" |
| 69 | + url = uri(rootProject.layout.buildDirectory.dir("staging-repo")) |
| 70 | + } |
| 71 | + } |
| 72 | + } |
| 73 | + |
| 74 | + signing { |
| 75 | + isRequired = (System.getenv("CI") == "true") |
| 76 | + val signingKey = project.findProperty("signing.key") as String? ?: System.getenv("SIGNING_KEY") |
| 77 | + val signingPassword = |
| 78 | + project.findProperty("signing.password") as String? ?: System.getenv("SIGNING_PASSWORD") |
| 79 | + if (!signingKey.isNullOrBlank() && !signingPassword.isNullOrBlank()) { |
| 80 | + useInMemoryPgpKeys(signingKey, signingPassword) |
| 81 | + } |
| 82 | + sign(publishing.publications["library"]) |
| 83 | + } |
| 84 | +} |
0 commit comments