From 35b20bd0f45252051ef4735db9f0103e2419096d Mon Sep 17 00:00:00 2001 From: carlosrfranco Date: Mon, 19 May 2025 11:04:54 -0300 Subject: [PATCH] Add maven publish task --- .github/workflows/release.yml | 9 ++++- build.gradle | 27 ++++++++++++-- gradle/publishing.gradle | 70 +++++++++++++++++++++++++++++++++++ 3 files changed, 102 insertions(+), 4 deletions(-) create mode 100644 gradle/publishing.gradle diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b4c7256..5c46edd 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -34,4 +34,11 @@ jobs: ${{ github.ref_name }} \ build/libs/multiline-regex-datacapture-filter-${{ steps.get_version.outputs.VERSION }}.jar env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Publish to Maven Central + run: ./gradlew -PsigningKey=${SIGNING_KEY_B64} -PsigningPassword=${SIGNING_PASSWORD} -PsonatypeUsername=${SONATYPE_USERNAME} -PsonatypePassword=${SONATYPE_PASSWORD} publishToSonatype closeAndReleaseSonatypeStagingRepository + env: + SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} + SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} + SIGNING_KEY_B64: ${{ secrets.SIGNING_KEY_B64 }} + SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }} \ No newline at end of file diff --git a/build.gradle b/build.gradle index 9e8ce18..6782130 100644 --- a/build.gradle +++ b/build.gradle @@ -2,14 +2,22 @@ plugins { id 'groovy' id 'java' id 'pl.allegro.tech.build.axion-release' version '1.7.1' + id 'io.github.gradle-nexus.publish-plugin' version '2.0.0' } -group 'com.rundeck.plugin' +group 'org.rundeck.plugins' + +ext.publishName = "Multiline Regex Datacapture Filter ${project.version}" +ext.publishDescription = project.description ?: 'Multiline Regex Datacapture Filter Plugin' +ext.githubSlug = 'rundeck-plugins/multiline-regex-datacapture-filter-plugin' +ext.developers = [ + [id: 'gschueler', name: 'Greg Schueler', email: 'greg@rundeck.com'] +] ext.rundeckVersion='5.11.1-20250415' defaultTasks 'clean','build' ext.rundeckPluginVersion= '1.2' -group 'com.rundeck.plugin' +group 'org.rundeck.plugins' scmVersion { ignoreUncommittedChanges = false @@ -29,7 +37,11 @@ scmVersion { } project.version = scmVersion.version -sourceCompatibility = 11 +java { + sourceCompatibility = JavaVersion.VERSION_11 + withJavadocJar() + withSourcesJar() +} /** @@ -88,3 +100,12 @@ jar { } //set jar task to depend on copyToLib jar.dependsOn(copyToLib) + +nexusPublishing { + packageGroup = 'org.rundeck.plugins' + repositories { + sonatype() + } +} + +apply from: "${rootDir}/gradle/publishing.gradle" diff --git a/gradle/publishing.gradle b/gradle/publishing.gradle new file mode 100644 index 0000000..5dddfcf --- /dev/null +++ b/gradle/publishing.gradle @@ -0,0 +1,70 @@ +/** + * Define project extension values in the project gradle file before including this file: + * + * publishName = 'Name of Package' + * publishDescription = 'description' (optional) + * githubSlug = Github slug e.g. 'rundeck/rundeck-cli' + * developers = [ [id:'id', name:'name', email: 'email' ] ] list of developers + * + * Define project properties to sign and publish when invoking publish task: + * + * ./gradlew \ + * -PsigningKey="base64 encoded gpg key" \ + * -PsigningPassword="password for key" \ + * -PsonatypeUsername="sonatype token user" \ + * -PsonatypePassword="sonatype token password" \ + * publishToSonatype closeAndReleaseSonatypeStagingRepository + */ +apply plugin: 'maven-publish' +apply plugin: 'signing' + +publishing { + publications { + "${project.name}"(MavenPublication) { publication -> + from components.java + + pom { + name = publishName + description = project.ext.hasProperty('publishDescription') ? project.ext.publishDescription : + project.description ?: publishName + url = "https://github.com/${githubSlug}" + licenses { + license { + name = 'The Apache Software License, Version 2.0' + url = 'http://www.apache.org/licenses/LICENSE-2.0.txt' + distribution = 'repo' + } + } + scm { + url = "https://github.com/${githubSlug}" + connection = "scm:git:git@github.com/${githubSlug}.git" + developerConnection = "scm:git:git@github.com:${githubSlug}.git" + } + if (project.ext.developers) { + developers { + project.ext.developers.each { dev -> + developer { + id = dev.id + name = dev.name + email = dev.email + } + } + } + } + } + + } + } +} +def base64Decode = { String prop -> + project.findProperty(prop) ? + new String(Base64.getDecoder().decode(project.findProperty(prop).toString())).trim() : + null +} + +if (project.hasProperty('signingKey') && project.hasProperty('signingPassword')) { + signing { + useInMemoryPgpKeys(base64Decode("signingKey"), project.signingPassword) + sign(publishing.publications) + } +}