@@ -381,6 +381,8 @@ artifacts {
381381publishing {
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
456510signing {
0 commit comments