Skip to content

Commit 1df57bd

Browse files
committed
publish fully versioned artifacts to maven.daporkchop.net
This eliminates the need to use JitPack or similar services to get maven artifacts pinned to a specific CubicChunks version.
1 parent 7165b37 commit 1df57bd

File tree

4 files changed

+132
-18
lines changed

4 files changed

+132
-18
lines changed

CubicChunksAPI/build.gradle.kts

Lines changed: 63 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,22 +138,23 @@ artifacts {
138138

139139
publishing {
140140
publications {
141-
create("mavenJava", MavenPublication::class) {
142-
version = project.ext["mavenProjectVersion"]!!.toString()
143-
artifactId = "cubicchunks-api"
144-
artifact(tasks["deobfSrcJar"]) {
141+
fun configureArtifacts(publication: MavenPublication) {
142+
publication.artifact(tasks["deobfSrcJar"]) {
145143
classifier = "sources"
146144
}
147-
artifact(tasks["allJar"]) {
145+
publication.artifact(tasks["allJar"]) {
148146
classifier = ""
149147
}
150-
artifact(tasks["javadocJar"]) {
148+
publication.artifact(tasks["javadocJar"]) {
151149
classifier = "javadoc"
152150
}
153-
artifact(tasks.jar) {
151+
publication.artifact(tasks.jar) {
154152
classifier = "dev"
155153
}
156-
pom {
154+
}
155+
156+
fun configurePom(publication: MavenPublication) {
157+
publication.pom {
157158
name.set("Cubic Chunks API")
158159
description.set("API for the CubicChunks mod for Minecraft")
159160
packaging = "jar"
@@ -187,9 +188,28 @@ publishing {
187188
}
188189
}
189190
}
191+
192+
create<MavenPublication>("mavenJava") {
193+
version = project.ext["mavenProjectVersion"]!!.toString()
194+
artifactId = "cubicchunks-api"
195+
196+
configureArtifacts(this)
197+
configurePom(this)
198+
}
199+
200+
//same as "mavenJava", but using the full project version from mcGitVersion instead of mavenProjectVersion.
201+
create<MavenPublication>("versionedMavenJava") {
202+
version = project.version.toString()
203+
artifactId = "cubicchunks-api"
204+
205+
configureArtifacts(this)
206+
configurePom(this)
207+
}
190208
}
191209
repositories {
192210
maven {
211+
name = "Sonatype"
212+
193213
val user = (project.properties["sonatypeUsername"] ?: System.getenv("sonatypeUsername")) as String?
194214
val pass = (project.properties["sonatypePassword"] ?: System.getenv("sonatypePassword")) as String?
195215
val local = user == null || pass == null
@@ -208,6 +228,41 @@ publishing {
208228
}
209229
}
210230
}
231+
232+
//only register maven.daporkchop.net repository if these environment variables are set
233+
val daporkchopMavenUsername = (project.properties["daporkchopMavenUsername"] ?: System.getenv("daporkchopMavenUsername")) as String?
234+
val daporkchopMavenPassword = (project.properties["daporkchopMavenPassword"] ?: System.getenv("daporkchopMavenPassword")) as String?
235+
if (daporkchopMavenUsername != null && daporkchopMavenPassword != null) {
236+
maven {
237+
name = "DaPorkchop_"
238+
239+
val releasesRepoUrl = "https://maven.daporkchop.net/release/"
240+
val snapshotsRepoUrl = "https://maven.daporkchop.net/snapshot/"
241+
242+
setUrl(if (doRelease.toBoolean()) releasesRepoUrl else snapshotsRepoUrl)
243+
credentials {
244+
username = daporkchopMavenUsername
245+
password = daporkchopMavenPassword
246+
}
247+
}
248+
}
249+
}
250+
251+
//all publish tasks should depend on all of the tasks which generate the artifacts being published
252+
tasks.withType<AbstractPublishToMaven>().configureEach {
253+
dependsOn("deobfSrcJar", "allJar", "javadocJar", "jar")
254+
}
255+
256+
//this is kinda gross, but is apparently the recommended way to conditionally publish specific publications to specific repositories:
257+
// see https://docs.gradle.org/current/userguide/publishing_customization.html#sec:publishing_maven:conditional_publishing
258+
tasks.withType<PublishToMavenRepository>().configureEach {
259+
val predicate = provider {
260+
(publication == publications["mavenJava"] && repository == repositories["Sonatype"]) ||
261+
(publication == publications["versionedMavenJava"] && repository == repositories["DaPorkchop_"])
262+
}
263+
onlyIf("publishing API to Sonatype repository, and versioned API to DaPorkchop_ repository") {
264+
predicate.get()
265+
}
211266
}
212267
}
213268

Jenkinsfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ pipeline {
5454
}
5555
}
5656
}
57+
stage("Publish") {
58+
steps {
59+
sh "./gradlew publish -x test"
60+
}
61+
}
5762
}
5863

5964
post {

build.gradle.kts

Lines changed: 63 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,8 @@ artifacts {
381381
publishing {
382382
repositories {
383383
maven {
384+
name = "Sonatype"
385+
384386
val user = (project.properties["sonatypeUsername"] ?: System.getenv("sonatypeUsername")) as String?
385387
val pass = (project.properties["sonatypePassword"] ?: System.getenv("sonatypePassword")) as String?
386388
val local = user == null || pass == null
@@ -399,24 +401,43 @@ publishing {
399401
}
400402
}
401403
}
404+
405+
//only register maven.daporkchop.net repository if these environment variables are set
406+
val daporkchopMavenUsername = (project.properties["daporkchopMavenUsername"] ?: System.getenv("daporkchopMavenUsername")) as String?
407+
val daporkchopMavenPassword = (project.properties["daporkchopMavenPassword"] ?: System.getenv("daporkchopMavenPassword")) as String?
408+
if (daporkchopMavenUsername != null && daporkchopMavenPassword != null) {
409+
maven {
410+
name = "DaPorkchop_"
411+
412+
val releasesRepoUrl = "https://maven.daporkchop.net/release/"
413+
val snapshotsRepoUrl = "https://maven.daporkchop.net/snapshot/"
414+
415+
setUrl(if (doRelease.toBoolean()) releasesRepoUrl else snapshotsRepoUrl)
416+
credentials {
417+
username = daporkchopMavenUsername
418+
password = daporkchopMavenPassword
419+
}
420+
}
421+
}
402422
}
403423
publications {
404-
create("mod", MavenPublication::class) {
405-
version = project.ext["mavenProjectVersion"]!!.toString()
406-
artifactId = "cubicchunks"
407-
artifact(tasks["shadowJar"]) {
424+
fun configureArtifacts(publication: MavenPublication) {
425+
publication.artifact(tasks["shadowJar"]) {
408426
classifier = ""
409427
}
410-
artifact(tasks["devShadowJar"]) {
428+
publication.artifact(tasks["devShadowJar"]) {
411429
classifier = "dev"
412430
}
413-
artifact(tasks["deobfSourcesJar"]) {
431+
publication.artifact(tasks["deobfSourcesJar"]) {
414432
classifier = "sources"
415433
}
416-
artifact(tasks["javadocJar"]) {
434+
publication.artifact(tasks["javadocJar"]) {
417435
classifier = "javadoc"
418436
}
419-
pom {
437+
}
438+
439+
fun configurePom(publication: MavenPublication) {
440+
publication.pom {
420441
name.set(projectName)
421442
description.set("Unlimited world height mod for Minecraft")
422443
packaging = "jar"
@@ -449,8 +470,41 @@ publishing {
449470
}
450471
}
451472
}
473+
474+
create<MavenPublication>("mod") {
475+
version = project.ext["mavenProjectVersion"]!!.toString()
476+
artifactId = "cubicchunks"
477+
478+
configureArtifacts(this)
479+
configurePom(this)
480+
}
481+
482+
//same as "mod", but using the full project version from mcGitVersion instead of mavenProjectVersion.
483+
create<MavenPublication>("versionedMod") {
484+
version = project.version.toString()
485+
artifactId = "cubicchunks"
486+
487+
configureArtifacts(this)
488+
configurePom(this)
489+
}
490+
}
491+
492+
//all publish tasks should depend on all of the tasks which generate the artifacts being published
493+
tasks.withType<AbstractPublishToMaven>().configureEach {
494+
dependsOn("shadowJar", "devShadowJar", "deobfSourcesJar", "javadocJar")
495+
}
496+
497+
//this is kinda gross, but is apparently the recommended way to conditionally publish specific publications to specific repositories:
498+
// see https://docs.gradle.org/current/userguide/publishing_customization.html#sec:publishing_maven:conditional_publishing
499+
tasks.withType<PublishToMavenRepository>().configureEach {
500+
val predicate = provider {
501+
(publication == publications["mod"] && repository == repositories["Sonatype"]) ||
502+
(publication == publications["versionedMod"] && repository == repositories["DaPorkchop_"])
503+
}
504+
onlyIf("publishing mod to Sonatype repository, and versioned mod to DaPorkchop_ repository") {
505+
predicate.get()
506+
}
452507
}
453-
tasks["publishModPublicationToMavenRepository"].dependsOn("shadowJar", "devShadowJar")
454508
}
455509

456510
signing {

jitpack.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ jdk:
22
- openjdk8
33
install:
44
- ./gradlew setupCiWorkspace
5-
- ./gradlew build publishToMavenLocal
5+
- ./gradlew build publishVersionedModPublicationToMavenLocal

0 commit comments

Comments
 (0)