Skip to content

Commit 027a229

Browse files
committed
Publish to Maven Central
1 parent e772947 commit 027a229

File tree

6 files changed

+326
-274
lines changed

6 files changed

+326
-274
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,17 @@ The developer api is quite rough, but that's where you can certainly help: I'll
141141
So, all I need is an indication about how you'd like that convenience layer to look like.
142142
Feel free to create an issue where we can discuss how your use case could be implemented!
143143

144+
## Release Workflow
145+
146+
There are multiple GitHub Action Workflows for the different steps in the package's lifecycle:
147+
148+
- CI: Builds and checks incoming changes on a pull request
149+
- triggered on every push to a non-default branch
150+
- CD: Publishes the Gradle artifacts to GitHub Package Registry
151+
- triggered only on pushes to the default branch
152+
- Release: Publishes Gradle artifacts to Sonatype and releases them to Maven Central
153+
- triggered on a published GitHub release using the underlying tag as artifact version, e.g. via `git tag -m "$MESSAGE" v$(date +"%Y-%m-%dT%H-%M-%S")`
154+
144155
## License
145156

146157
Copyright 2015-2021 [Tobias Gesellchen](https://www.gesellix.net/) ([@gesellix](https://twitter.com/gesellix))

build.gradle.kts

Lines changed: 49 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,74 @@
1-
import java.text.SimpleDateFormat
21
import java.util.*
32

4-
rootProject.extra.set("artifactVersion", SimpleDateFormat("yyyy-MM-dd\'T\'HH-mm-ss").format(Date()))
5-
63
buildscript {
7-
repositories {
8-
mavenLocal()
9-
jcenter()
10-
gradlePluginPortal()
11-
mavenCentral()
12-
}
4+
repositories {
5+
gradlePluginPortal()
6+
mavenCentral()
7+
}
138
}
149

1510
plugins {
16-
id("com.github.ben-manes.versions") version "0.33.0"
17-
id("com.jfrog.bintray") version "1.8.5" apply false
18-
id("net.ossindex.audit") version "0.4.11"
19-
id("io.freefair.github.package-registry-maven-publish") version "5.2.1" // apply false
11+
id("maven-publish")
12+
id("com.github.ben-manes.versions") version "0.36.0"
13+
id("net.ossindex.audit") version "0.4.11"
14+
id("io.freefair.maven-central.validate-poms") version "5.3.0"
15+
id("io.github.gradle-nexus.publish-plugin") version "1.0.0"
2016
}
2117

2218
val dependencyVersions = listOf(
23-
"junit:junit:4.13",
24-
"org.codehaus.groovy:groovy:2.5.13",
25-
"org.codehaus.groovy:groovy-json:2.5.13",
26-
"org.codehaus.groovy:groovy-macro:2.5.13",
27-
"org.codehaus.groovy:groovy-nio:2.5.13",
28-
"org.codehaus.groovy:groovy-sql:2.5.13",
29-
"org.codehaus.groovy:groovy-templates:2.5.13",
30-
"org.codehaus.groovy:groovy-test:2.5.13",
31-
"org.codehaus.groovy:groovy-xml:2.5.13"
19+
"junit:junit:4.13",
20+
"org.codehaus.groovy:groovy:2.5.13",
21+
"org.codehaus.groovy:groovy-json:2.5.13",
22+
"org.codehaus.groovy:groovy-macro:2.5.13",
23+
"org.codehaus.groovy:groovy-nio:2.5.13",
24+
"org.codehaus.groovy:groovy-sql:2.5.13",
25+
"org.codehaus.groovy:groovy-templates:2.5.13",
26+
"org.codehaus.groovy:groovy-test:2.5.13",
27+
"org.codehaus.groovy:groovy-xml:2.5.13",
28+
"org.squareup.moshi:moshi:1.11.0",
29+
"org.squareup.moshi:moshi-kotlin:1.11.0",
30+
"org.squareup.okhttp3:okhttp:4.9.0",
31+
"org.squareup.okio:okio:2.9.0"
3232
)
3333

34-
subprojects {
35-
configurations.all {
36-
resolutionStrategy {
37-
failOnVersionConflict()
38-
force(dependencyVersions)
34+
val dependencyGroupVersions = mapOf<String, String>()
35+
36+
allprojects {
37+
configurations.all {
38+
resolutionStrategy {
39+
failOnVersionConflict()
40+
force(dependencyVersions)
41+
eachDependency {
42+
val forcedVersion = dependencyGroupVersions[requested.group]
43+
if (forcedVersion != null) {
44+
useVersion(forcedVersion)
3945
}
46+
}
4047
}
48+
}
4149
}
4250

4351
fun findProperty(s: String) = project.findProperty(s) as String?
4452

45-
rootProject.github {
46-
slug.set("${project.property("github.package-registry.owner")}/${project.property("github.package-registry.repository")}")
47-
username.set(System.getenv("GITHUB_ACTOR") ?: findProperty("github.package-registry.username"))
48-
token.set(System.getenv("GITHUB_TOKEN") ?: findProperty("github.package-registry.password"))
49-
}
50-
5153
tasks {
5254
wrapper {
5355
gradleVersion = "6.8.2"
5456
distributionType = Wrapper.DistributionType.ALL
5557
}
5658
}
5759

60+
val isSnapshot = project.version == "unspecified"
61+
nexusPublishing {
62+
repositories {
63+
if (!isSnapshot) {
64+
sonatype {
65+
// 'sonatype' is pre-configured for Sonatype Nexus (OSSRH) which is used for The Central Repository
66+
stagingProfileId.set(System.getenv("SONATYPE_STAGING_PROFILE_ID") ?: findProperty("sonatype.staging.profile.id")) //can reduce execution time by even 10 seconds
67+
username.set(System.getenv("SONATYPE_USERNAME") ?: findProperty("sonatype.username"))
68+
password.set(System.getenv("SONATYPE_PASSWORD") ?: findProperty("sonatype.password"))
69+
}
70+
}
71+
}
72+
}
73+
5874
project.apply("debug.gradle.kts")

0 commit comments

Comments
 (0)