From 45c7a38c07ea98d3c7f4edbfbb8c5624ff2444cf Mon Sep 17 00:00:00 2001 From: TheMCLoveMan Date: Tue, 27 Feb 2024 23:07:27 +0100 Subject: [PATCH] publishing --- build.gradle | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/build.gradle b/build.gradle index 8bc34c4..c8c8118 100644 --- a/build.gradle +++ b/build.gradle @@ -3,6 +3,7 @@ plugins { id 'idea' id 'maven-publish' id 'net.minecraftforge.gradle' version '6.+' + id 'me.shedaniel.unified-publishing' version '0.1.+' } group = 'net.themcbrothers' @@ -165,6 +166,96 @@ artifacts { jar.finalizedBy('reobfJar') +publishing { + publications { PublicationContainer publicationContainer -> + publicationContainer.register('mavenJava', MavenPublication) { MavenPublication publication -> + from components.java + publication.artifactId = archive_base + publication.version = "$minecraft_version-$mod_version" + } + } + repositories { + maven { + credentials { + username = System.getenv('PUBLISH_USER') + password = System.getenv('PUBLISH_PASSWORD') + } + + url 'https://nexus.themcbrothers.net/repository/maven-releases/' + } + } +} + +private String getChangelogText(boolean hasTitle) { + File changelogFile = file('changelog.txt') + String str = '' + int lineCount = 0 + boolean done = false + changelogFile.eachLine { + if (done || it == null) { + return + } + if (it.length() > 1) { + String temp = it + if (lineCount == 0) { + temp = hasTitle ? "## $mod_name $mod_version" : '' + } else if (it.startsWith('-')) { + temp = temp.replaceAll("(\\S+/\\S+)#(\\d+)\\b", "[\$0](https://github.com/\$1/issues/\$2)") + temp = temp.replaceAll("#(\\d+)\\b(?!)", "[\$0](https://github.com/$github_repo/issues/\$1)") + } else { + temp = "#### $temp" + } + str += "$temp\n" + lineCount++ + return + } else { + done = true + } + return + } + return str +} + +unifiedPublishing { + project { + version = "$minecraft_version-$mod_version" + displayName = "[$minecraft_version] v$mod_version" + releaseType = project.artifact_type + gameVersions = [minecraft_version] + gameLoaders = ["forge"] + + mainPublication tasks.jar + + var curseforgeToken = System.getenv('CURSEFORGE_TOKEN') + var modrinthToken = System.getenv('MODRINTH_TOKEN') + + if (curseforgeToken != null) { + curseforge { + token = curseforgeToken + id = project.curse_project + changelog = getChangelogText(true) + gameVersions.addAll "Java 17" + + relations { + optional "jei" + } + } + } + + if (modrinthToken != null) { + modrinth { + token = modrinthToken + id = project.modrinth_project + changelog = getChangelogText(false) + + relations { + optional "jei" + } + } + } + } +} + tasks.withType(JavaCompile).configureEach { options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation } \ No newline at end of file