Last active
May 3, 2026 16:57
-
-
Save Lothrazar/373c8f85900d5eb3a47cf93effc8aa7c to your computer and use it in GitHub Desktop.
publish to Modrinth minecraft gradle neoforge 1.21.1+
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| plugins { | |
| id 'java-library' | |
| id 'maven-publish' | |
| id 'net.neoforged.moddev' version '2.0.141' | |
| id 'idea' | |
| // ... add this plugin | |
| id 'com.modrinth.minotaur' version '2.8.7' apply false | |
| } | |
| // then tuck this inside your build.gradle, or standalone file using apply from: | |
| // requires SECRET key in user gradle | |
| // modrinth_token= # https://modrinth.com/settings/pats | |
| apply plugin: 'com.modrinth.minotaur' | |
| def changelogText = (new groovy.json.JsonSlurper().parse(file('update.json'))[minecraft_version]?[mod_version] ?: '') as String | |
| def mrToken = findProperty('modrinth_token') ?: deployProps.getProperty('modrinth_token', '') ?: System.getenv('MODRINTH_TOKEN') ?: '' | |
| // Exposed as ext so publishCurseForge in build.gradle can read them after apply from: | |
| ext.cfApiKey = findProperty('curseforge_api_key') ?: deployProps.getProperty('curseforge_api_key', '') ?: System.getenv('CURSEFORGE_API_KEY') ?: '' | |
| ext.changelog = changelogText | |
| // --- Modrinth --- | |
| modrinth { | |
| token = mrToken | |
| projectId = modrinth_id | |
| versionNumber = project.version | |
| versionType = 'release' | |
| uploadFile = jar | |
| gameVersions = [minecraft_version] | |
| loaders = ['neoforge'] | |
| changelog = changelogText | |
| } | |
| // important: unlike curseforge, modrinth has no problem with you making many copies of the same version | |
| //so we have to hand roll up our own checke | |
| tasks.named('modrinth').configure { | |
| notCompatibleWithConfigurationCache('Minotaur is not configuration-cache compatible') | |
| doFirst { | |
| if (!modrinth_id?.trim()) { | |
| logger.warn(""" | |
| ================================================================================ | |
| MODRINTH PROJECT NOT CONFIGURED — ${project.name} | |
| ================================================================================ | |
| 'modrinth_id' is empty. You must create the Modrinth project by hand first: | |
| 1. Go to https://modrinth.com/dashboard and create a new project | |
| 2. Copy the project ID (shown on the project settings page) | |
| 3. Open gradle.properties in this subproject | |
| 4. Set: modrinth_id=<your-project-id> | |
| This cannot be automated — Modrinth requires manual project creation. | |
| ================================================================================ | |
| """) | |
| throw new StopExecutionException() | |
| } | |
| def versions = new groovy.json.JsonSlurper() | |
| .parse(new URI("https://api.modrinth.com/v2/project/${modrinth_id}/version").toURL()) | |
| if (versions.any { it.version_number == project.version }) { | |
| throw new GradleException("Modrinth version ${modrinth_id}-${project.version} already exists — bump mod_version before publishing.") | |
| } | |
| } | |
| } | |
| tasks.register('publishModrinth') { | |
| group = 'publishing' | |
| description = 'Uploads the mod jar to Modrinth.' | |
| dependsOn 'modrinth' | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment