Skip to content

Commit a9fca3f

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 0ed46d9 commit a9fca3f

File tree

3 files changed

+69
-9
lines changed

3 files changed

+69
-9
lines changed

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: 62 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,8 @@ artifacts {
320320
publishing {
321321
repositories {
322322
maven {
323+
name = "Sonatype"
324+
323325
val user = (project.properties["sonatypeUsername"] ?: System.getenv("sonatypeUsername")) as String?
324326
val pass = (project.properties["sonatypePassword"] ?: System.getenv("sonatypePassword")) as String?
325327
val local = user == null || pass == null
@@ -338,21 +340,40 @@ publishing {
338340
}
339341
}
340342
}
343+
344+
//only register maven.daporkchop.net repository if these environment variables are set
345+
val daporkchopMavenUsername = (project.properties["daporkchopMavenUsername"] ?: System.getenv("daporkchopMavenUsername")) as String?
346+
val daporkchopMavenPassword = (project.properties["daporkchopMavenPassword"] ?: System.getenv("daporkchopMavenPassword")) as String?
347+
if (daporkchopMavenUsername != null && daporkchopMavenPassword != null) {
348+
maven {
349+
name = "DaPorkchop_"
350+
351+
val releasesRepoUrl = "https://maven.daporkchop.net/release/"
352+
val snapshotsRepoUrl = "https://maven.daporkchop.net/snapshot/"
353+
354+
setUrl(if (doRelease.toBoolean()) releasesRepoUrl else snapshotsRepoUrl)
355+
credentials {
356+
username = daporkchopMavenUsername
357+
password = daporkchopMavenPassword
358+
}
359+
}
360+
}
341361
}
342362
publications {
343-
create("mod", MavenPublication::class) {
344-
version = project.ext["mavenProjectVersion"]!!.toString()
345-
artifactId = base.archivesBaseName.toLowerCase()
346-
artifact(tasks["sourcesJar"]) {
363+
fun configureArtifacts(publication: MavenPublication) {
364+
publication.artifact(tasks["sourcesJar"]) {
347365
classifier = "sources"
348366
}
349-
artifact(tasks["shadowJar"]) {
367+
publication.artifact(tasks["shadowJar"]) {
350368
classifier = ""
351369
}
352-
artifact(tasks["devShadowJar"]) {
370+
publication.artifact(tasks["devShadowJar"]) {
353371
classifier = "dev"
354372
}
355-
pom {
373+
}
374+
375+
fun configurePom(publication: MavenPublication) {
376+
publication.pom {
356377
name.set(projectName)
357378
description.set("CubicChunks customizable world generator")
358379
packaging = "jar"
@@ -385,8 +406,41 @@ publishing {
385406
}
386407
}
387408
}
409+
410+
create<MavenPublication>("mod") {
411+
version = project.ext["mavenProjectVersion"]!!.toString()
412+
artifactId = base.archivesBaseName.toLowerCase()
413+
414+
configureArtifacts(this)
415+
configurePom(this)
416+
}
417+
418+
//same as "mod", but using the full project version from mcGitVersion instead of mavenProjectVersion.
419+
create<MavenPublication>("versionedMod") {
420+
version = project.version.toString()
421+
artifactId = base.archivesBaseName.toLowerCase()
422+
423+
configureArtifacts(this)
424+
configurePom(this)
425+
}
426+
}
427+
428+
//all publish tasks should depend on all of the tasks which generate the artifacts being published
429+
tasks.withType<AbstractPublishToMaven>().configureEach {
430+
dependsOn("sourcesJar", "shadowJar", "devShadowJar")
431+
}
432+
433+
//this is kinda gross, but is apparently the recommended way to conditionally publish specific publications to specific repositories:
434+
// see https://docs.gradle.org/current/userguide/publishing_customization.html#sec:publishing_maven:conditional_publishing
435+
tasks.withType<PublishToMavenRepository>().configureEach {
436+
val predicate = provider {
437+
(publication == publications["mod"] && repository == repositories["Sonatype"]) ||
438+
(publication == publications["versionedMod"] && repository == repositories["DaPorkchop_"])
439+
}
440+
onlyIf("publishing mod to Sonatype repository, and versioned mod to DaPorkchop_ repository") {
441+
predicate.get()
442+
}
388443
}
389-
tasks["publishModPublicationToMavenRepository"].dependsOn("sourcesJar", "shadowJar", "devShadowJar")
390444
}
391445

392446
signing {

jitpack.yml

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

0 commit comments

Comments
 (0)