Skip to content

Commit 35b467e

Browse files
committed
Using JReleaser to publish junit4 to GitHub Packages and Maven Central
1 parent 2d64183 commit 35b467e

File tree

1 file changed

+62
-21
lines changed

1 file changed

+62
-21
lines changed

junit4/build.gradle

Lines changed: 62 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,21 @@ plugins {
22
id 'com.android.library'
33
id 'de.mannodermaus.android-junit5'
44
id 'maven-publish'
5-
id 'signing'
5+
id 'org.jreleaser'
66
}
77

88
def libraryGroup = 'io.github.neboskreb'
99
def libraryArtifact = 'android-log4j2-junit4'
1010
def libraryVersion = '2.24.1-SNAPSHOT'
1111

12+
final stagingDirectory = layout.buildDirectory.dir('staging-deploy')
13+
1214
afterEvaluate {
1315
publishing {
1416
repositories {
1517
maven {
16-
name = "github-packages"
17-
url = uri("https://maven.pkg.github.com/neboskreb/android-log4j2")
18-
credentials {
19-
username = project.findProperty("github_packages_user") ?: System.getenv("PACKAGES_USERNAME")
20-
password = project.findProperty("github_packages_token") ?: System.getenv("PACKAGES_TOKEN")
21-
}
22-
}
23-
maven {
24-
name "MavenCentral"
25-
if (version.endsWith('SNAPSHOT')) {
26-
url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
27-
} else {
28-
url = uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/")
29-
}
30-
credentials {
31-
username = project.findProperty("mavenCentralUser") ?: System.getenv("MAVEN_USERNAME")
32-
password = project.findProperty("mavenCentralPass") ?: System.getenv("MAVEN_PASSWORD")
33-
}
18+
name = 'staging'
19+
url = stagingDirectory
3420
}
3521
}
3622

@@ -71,8 +57,58 @@ afterEvaluate {
7157
}
7258
}
7359

74-
signing {
75-
sign publishing.publications.release
60+
jreleaser {
61+
gitRootSearch = true
62+
signing {
63+
active = 'RELEASE'
64+
armored = true
65+
verify = false
66+
67+
version = libraryVersion
68+
69+
secretKey = getConfiguredValue('signing.key.armored', 'PGP_SIGNING_KEY_ARMORED')
70+
passphrase = getConfiguredValue('signing.password', 'PGP_SIGNING_PASSWORD')
71+
}
72+
deploy {
73+
maven {
74+
final String staging = stagingDirectory.get().toString()
75+
76+
github {
77+
packages {
78+
active = 'RELEASE'
79+
url = 'https://maven.pkg.github.com/neboskreb/android-log4j2'
80+
stagingRepository(staging)
81+
82+
sign = true
83+
84+
username = getConfiguredValue('github_packages_user', 'PACKAGES_USERNAME')
85+
password = getConfiguredValue('github_packages_token', 'PACKAGES_TOKEN')
86+
}
87+
}
88+
89+
mavenCentral {
90+
sonatype {
91+
active = 'RELEASE'
92+
url = 'https://central.sonatype.com/api/v1/publisher'
93+
stagingRepository(staging)
94+
95+
sign = true
96+
97+
username = getConfiguredValue('mavenCentralUser', 'MAVEN_USERNAME')
98+
password = getConfiguredValue('mavenCentralPass', 'MAVEN_PASSWORD')
99+
100+
// Android release contains .aar instead of .jar, which is not currently supported by the rules validator.
101+
// See https://github.com/jreleaser/jreleaser.github.io/issues/85
102+
// TODO re-enable the rules check once the .aar is supported
103+
applyMavenCentralRules = false
104+
}
105+
}
106+
}
107+
}
108+
}
109+
110+
tasks.named('jreleaserDeploy') {
111+
dependsOn publishReleasePublicationToStagingRepository
76112
}
77113
}
78114

@@ -121,3 +157,8 @@ dependencies {
121157
androidTestImplementation 'androidx.test:runner:1.7.0'
122158
androidTestImplementation 'junit:junit:4.13.2'
123159
}
160+
161+
162+
private String getConfiguredValue(String projectProperty, String environmentVariable) {
163+
return project.findProperty(projectProperty) ?: System.getenv(environmentVariable)
164+
}

0 commit comments

Comments
 (0)