Skip to content

Instantly share code, notes, and snippets.

@JamiesWhiteShirt
Last active October 18, 2021 15:59
Show Gist options
  • Save JamiesWhiteShirt/a2b76fcaa74bb17e202aff884774ba92 to your computer and use it in GitHub Desktop.
Save JamiesWhiteShirt/a2b76fcaa74bb17e202aff884774ba92 to your computer and use it in GitHub Desktop.
How to publish your Fabric mod with CurseGradle

How to publish your Fabric mod with CurseGradle

CurseGradle is a Gradle plugin that lets you publish artifacts to CurseForge. Consult the CurseGradle wiki for the full details. It works out of the box for ForgeGradle projects, but requires a bit of configuration for Fabric projects, which is the subject of this gist.

CurseGradle will assume the environment is a ForgeGradle environment, so its integration has to be manually switched off. Without ForgeGradle, CurseGradle doesn't know which Minecraft version you are working with, so it has to be specified manually. The correct main artifact is the output of the remapJar task.

The curseforge section of the buildscript should contain at least the following:

curseforge {
    ...
    project {
        id = PROJECT_ID
        addGameVersion "1.14-Snapshot"
        mainArtifact(remapJar.jar)
        ....
    }
    options {
        forgeGradleIntegration = false
    }
}

One problem remains - The curseforge publishing task does not depend on the remapJar task. By making the curseforge publishing task depend on the remapJar task we ensure the file is up-to-date when uploaded.

This can be fixed with the following hack:

afterEvaluate {
    tasks.curseforgePROJECT_ID.dependsOn remapJar
}

CurseGradle generates a publish task for the project in afterEvaluate, which we can only access in our own afterEvaluate. The name of the publish task is based on the project ID. We can then make the publish task depend on the remapJar task.

plugins {
id "fabric-loom" version "0.2.0-SNAPSHOT"
id "com.matthewprenger.cursegradle" version "1.1.2"
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
archivesBaseName = "example"
version = "1.0.0"
minecraft {
}
dependencies {
minecraft "com.mojang:minecraft:19w02a"
mappings "net.fabricmc:yarn:19w02a.13"
modCompile "net.fabricmc:fabric-loader:0.3.2.92"
// Fabric API. This is technically optional, but you probably want it anyway.
modCompile "net.fabricmc:fabric:0.1.4.71"
}
curseforge {
if (project.hasProperty("curseForgeApiKey")) {
apiKey = project.properties.curseForgeApiKey
}
project {
id = "123456"
addGameVersion "1.14-Snapshot"
mainArtifact(remapJar.jar) {
displayName = "Example $project.version"
}
}
options {
forgeGradleIntegration = false
}
}
afterEvaluate {
tasks.curseforge123456.dependsOn remapJar
}
@ZuzAser80
Copy link

Thanks, i really needed that :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment