GitHub: https://github.com/SafiBank/SaFiMono/tree/main/common/library-publisher-plugin

Overview

Gradle plugin that unifies and simplifies publishing of common libraries to maven repository.

How it works

LibraryPublisherPlugin performs following actions:

  • applies MavenPublishPlugin (for publishing in Maven format to Maven repository) and ArtifactRegistryGradlePlugin (for authentication against GCP artifact registry)

  • creates MavenPublication (configuration of how Gradle should publish something in Maven format) that will be later configured by user of this plugin

Usage

On the client/user (common library) side, following steps need to be done:

  • repositories for plugins need to be set in settings.gradle.kts - apart from implicit gradlePluginPortal, we need to add our maven repository by specifying this top level property:

pluginManagement {
    repositories {
        gradlePluginPortal()
        maven {
            url = uri("https://asia-southeast1-maven.pkg.dev/safi-repos/safi-maven")
        }
    }
}
  • in build.gradle.kts, plugins maven-publish and com.google.cloud.artifactregistry.gradle-plugin should be removed and replaced by

id("ph.safibank.common.library.publisher") version "1.+"
  • in build.gradle.kts, entire publishing section should be removed

  • in settings.gradle.kts, rootProject.name should be properly set - it will be the artifactId of the resulting artifact

  • in gradle.properties, new variable named libraryMajorVersion should be set to the value that will be used as the first part of the versionId (the second part will be the timestamp)

Outcome

The outcome of running gradle publish will be library artifact deployed to maven repository:

  • maven repo is defined by LibraryPublisherPlugin.mavenRepoUri ("https://asia-southeast1-maven.pkg.dev/safi-repos/safi-maven" at the time of writing)

  • groupId is defined by LibraryPublisherPlugin.groupId ("ph.safibank.common" at the time of writing)

  • artifactId is defined as "${project.properties["libraryMajorVersion"]}.SimpleDateFormat("yyyyMMdd-HHmmss").format(Date())" (e.g. 1.20220630-140000)