Skip to content

Commit efe48fa

Browse files
committed
Add Maven Publishing.
1 parent 07be7aa commit efe48fa

3 files changed

Lines changed: 122 additions & 33 deletions

File tree

.github/workflows/release.yml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
on:
22
push:
3-
# Sequence of patterns matched against refs/tags
43
tags:
5-
- '*' # Push events to matching v*, i.e. v1.0, v20.15.10
4+
- '*.*.*'
65

7-
name: Upload Release Asset
6+
name: Publish Release
87

98
jobs:
109
build:
11-
name: Upload Release Asset
10+
name: Publish Release
1211
runs-on: ubuntu-latest
1312
steps:
1413
- name: Checkout code
@@ -25,8 +24,7 @@ jobs:
2524
- name: Get Release Version
2625
id: get_version
2726
run: VERSION=$(./gradlew currentVersion -q -Prelease.quiet) && echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
28-
- name: Create Release and Upload Asset
29-
id: create_release
27+
- name: Create Release
3028
run: |
3129
gh release create \
3230
--generate-notes \
@@ -35,3 +33,10 @@ jobs:
3533
build/libs/http-notification-${{ steps.get_version.outputs.VERSION }}.jar
3634
env:
3735
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36+
- name: Publish to Maven Central
37+
run: ./gradlew -PsigningKey=${SIGNING_KEY_B64} -PsigningPassword=${SIGNING_PASSWORD} -PsonatypeUsername=${SONATYPE_USERNAME} -PsonatypePassword=${SONATYPE_PASSWORD} publishToSonatype closeAndReleaseSonatypeStagingRepository
38+
env:
39+
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
40+
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
41+
SIGNING_KEY_B64: ${{ secrets.SIGNING_KEY_B64 }}
42+
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}

build.gradle

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,16 @@ plugins {
22
id 'pl.allegro.tech.build.axion-release' version '1.17.2'
33
id 'groovy'
44
id 'java'
5-
id 'maven-publish'
5+
id 'io.github.gradle-nexus.publish-plugin' version '2.0.0'
66
}
77

8-
group 'com.rundeck.plugins'
8+
group 'org.rundeck.plugins'
9+
10+
ext.publishName = "Http Notification ${project.version}"
11+
ext.githubSlug = 'rundeck-plugins/http-notification'
12+
ext.developers = [
13+
[id: 'gschueler', name: 'Greg Schueler', email: 'greg@rundeck.com']
14+
]
915

1016
scmVersion {
1117
ignoreUncommittedChanges = false
@@ -17,8 +23,12 @@ scmVersion {
1723

1824
version = scmVersion.version // Dynamic version from git tag
1925

20-
sourceCompatibility = 17
21-
targetCompatibility = 17
26+
java {
27+
sourceCompatibility = JavaVersion.VERSION_17
28+
targetCompatibility = JavaVersion.VERSION_17
29+
withSourcesJar()
30+
withJavadocJar()
31+
}
2232
ext.rundeckPluginVersion = '1.2'
2333
ext.pluginClassNames='com.rundeck.plugin.HttpNotificationPlugin'
2434
ext.pluginName = 'Http Notification'
@@ -47,15 +57,16 @@ repositories {
4757
name = "PackageCloudTest"
4858
url = uri("https://packagecloud.io/pagerduty/rundeckpro-test/maven2")
4959
content {
50-
includeGroup('com.rundeck.plugins')
60+
includeGroup('org.rundeck.plugins')
5161
}
5262
}
5363
mavenCentral()
5464
}
5565

5666
dependencies {
5767
implementation 'org.apache.groovy:groovy-all:4.0.29'
58-
implementation 'org.rundeck:rundeck-core:6.0.0-SNAPSHOT'
68+
compileOnly 'org.rundeck:rundeck-core:6.0.0-SNAPSHOT'
69+
testImplementation 'org.rundeck:rundeck-core:6.0.0-SNAPSHOT'
5970

6071
// Apache HTTP client dependencies for compilation (http-step bundles these but doesn't expose them transitively)
6172
implementation 'org.apache.httpcomponents:httpclient:4.5.14'
@@ -64,7 +75,7 @@ dependencies {
6475

6576
// Bundle http-step plugin in lib/ directory for runtime
6677
// Use transitive=false to avoid duplicating dependencies already bundled in http-step JAR
67-
pluginLibs ('com.rundeck.plugins:http-step:1.1.20-grails7') {
78+
pluginLibs ('org.rundeck.plugins:http-step:1.1.20-grails7') {
6879
transitive = false
6980
}
7081

@@ -112,27 +123,14 @@ test {
112123
]
113124
}
114125

115-
publishing {
116-
publications {
117-
maven(MavenPublication) {
118-
groupId = 'com.rundeck.plugins'
119-
artifactId = 'http-notification'
120-
version = project.version
121-
from components.java
122-
}
123-
}
124-
126+
nexusPublishing {
127+
packageGroup = 'org.rundeck.plugins'
125128
repositories {
126-
maven {
127-
name = "PackageCloudTest"
128-
url = uri("https://packagecloud.io/pagerduty/rundeckpro-test/maven2")
129-
authentication {
130-
header(HttpHeaderAuthentication)
131-
}
132-
credentials(HttpHeaderCredentials) {
133-
name = "Authorization"
134-
value = "Bearer " + (System.getenv("PKGCLD_WRITE_TOKEN") ?: project.findProperty("pkgcldWriteToken"))
135-
}
129+
sonatype {
130+
nexusUrl.set(uri("https://ossrh-staging-api.central.sonatype.com/service/local/"))
131+
snapshotRepositoryUrl.set(uri("https://central.sonatype.com/repository/maven-snapshots/"))
136132
}
137133
}
138134
}
135+
136+
apply from: "${rootDir}/gradle/publishing.gradle"

gradle/publishing.gradle

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/**
2+
* Define project extension values in the project gradle file before including this file:
3+
*
4+
* publishName = 'Name of Package'
5+
* publishDescription = 'description' (optional)
6+
* githubSlug = Github slug e.g. 'rundeck/rundeck-cli'
7+
* developers = [ [id:'id', name:'name', email: 'email' ] ] list of developers
8+
*
9+
* Define project properties to sign and publish when invoking publish task:
10+
*
11+
* ./gradlew \
12+
* -PsigningKey="base64 encoded gpg key" \
13+
* -PsigningPassword="password for key" \
14+
* -PsonatypeUsername="sonatype token user" \
15+
* -PsonatypePassword="sonatype token password" \
16+
* publishToSonatype closeAndReleaseSonatypeStagingRepository
17+
*/
18+
apply plugin: 'maven-publish'
19+
apply plugin: 'signing'
20+
21+
publishing {
22+
publications {
23+
"${project.name}"(MavenPublication) { publication ->
24+
from components.java
25+
26+
pom {
27+
name = publishName
28+
description = project.ext.hasProperty('publishDescription') ? project.ext.publishDescription :
29+
project.description ?: publishName
30+
url = "https://github.com/${githubSlug}"
31+
licenses {
32+
license {
33+
name = 'The Apache Software License, Version 2.0'
34+
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
35+
distribution = 'repo'
36+
}
37+
}
38+
scm {
39+
url = "https://github.com/${githubSlug}"
40+
connection = "scm:git:git@github.com/${githubSlug}.git"
41+
developerConnection = "scm:git:git@github.com:${githubSlug}.git"
42+
}
43+
if (project.ext.developers) {
44+
developers {
45+
project.ext.developers.each { dev ->
46+
developer {
47+
id = dev.id
48+
name = dev.name
49+
email = dev.email
50+
}
51+
}
52+
}
53+
}
54+
}
55+
56+
}
57+
}
58+
repositories {
59+
def pkgcldWriteToken = System.getenv("PKGCLD_WRITE_TOKEN") ?: project.findProperty("pkgcldWriteToken")
60+
if (pkgcldWriteToken) {
61+
maven {
62+
name = "PackageCloudTest"
63+
url = uri("https://packagecloud.io/pagerduty/rundeckpro-test/maven2")
64+
authentication {
65+
header(HttpHeaderAuthentication)
66+
}
67+
credentials(HttpHeaderCredentials) {
68+
name = "Authorization"
69+
value = "Bearer " + pkgcldWriteToken
70+
}
71+
}
72+
}
73+
}
74+
}
75+
def base64Decode = { String prop ->
76+
project.findProperty(prop) ?
77+
new String(Base64.getDecoder().decode(project.findProperty(prop).toString())).trim() :
78+
null
79+
}
80+
81+
if (project.hasProperty('signingKey') && project.hasProperty('signingPassword')) {
82+
signing {
83+
useInMemoryPgpKeys(base64Decode("signingKey"), project.signingPassword)
84+
sign(publishing.publications)
85+
}
86+
}

0 commit comments

Comments
 (0)