1- @file:Suppress(" UnstableApiUsage" , " PropertyName" )
2-
3- import dev.deftu.gradle.utils.GameSide
4- import dev.deftu.gradle.utils.includeOrShade
5- import dev.deftu.gradle.utils.version.MinecraftVersion
6- import dev.deftu.gradle.utils.version.MinecraftVersions
1+ import org.jetbrains.kotlin.gradle.dsl.JvmTarget
2+ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
73
84plugins {
9- java
10- kotlin(" jvm" )
11- id(" dev.deftu.gradle.multiversion" ) // Applies preprocessing for multiple versions of Minecraft and/or multiple mod loaders.
12- id(" dev.deftu.gradle.tools" ) // Applies several configurations to things such as the Java version, project name/version, etc.
13- id(" dev.deftu.gradle.tools.resources" ) // Applies resource processing so that we can replace tokens, such as our mod name/version, in our resources.
14- id(" dev.deftu.gradle.tools.bloom" ) // Applies the Bloom plugin, which allows us to replace tokens in our source files, such as being able to use `@MOD_VERSION` in our source files.
15- id(" dev.deftu.gradle.tools.minecraft.loom" ) // Applies the Loom plugin, which automagically configures Essential's Architectury Loom plugin for you.
16- id(" dev.deftu.gradle.tools.shadow" ) // Applies the Shadow plugin, which allows us to shade our dependencies into our mod JAR. This is NOT recommended for Fabric mods, but we have an *additional* configuration for those!
17- id(" dev.deftu.gradle.tools.minecraft.releases" ) // Applies the Minecraft auto-releasing plugin, which allows you to automatically release your mod to CurseForge and Modrinth.
5+ kotlin(" jvm" ) version " 2.3.0"
6+ id(" net.fabricmc.fabric-loom-remap" ) version " 1.14-SNAPSHOT"
7+ id(" dev.deftu.gradle.bloom" ) version " 0.2.0"
8+ id(" me.modmuss50.mod-publish-plugin" ) version " 1.1.0"
189}
1910
20- if (mcData.isForge) {
21- loom.forge.mixinConfig(" mixins.crashpatch.init.json" )
11+ val modid = property(" mod.id" )
12+ val modname = property(" mod.name" )
13+ val modversion = property(" mod.version" )
14+ val mcversion = stonecutter.current.version
15+ val oneconfigversion = property(" oneconfig_version" )
16+
17+ version = " $modversion +$mcversion "
18+ base.archivesName = modname.toString()
19+
20+ repositories {
21+ maven(" https://maven.parchmentmc.org" )
22+ maven(" https://repo.polyfrost.org/releases" )
23+ maven(" https://repo.polyfrost.org/snapshots" )
24+ maven(" https://api.modrinth.com/maven" ) {
25+ content { includeGroup(" maven.modrinth" ) }
26+ }
27+ maven(" https://maven.bawnorton.com/releases" ) {
28+ content { includeGroup(" com.github.bawnorton.mixinsquared" ) }
29+ }
2230}
2331
24- toolkitLoomHelper {
25- useOneConfig {
26- version = " 1.0.0-alpha.171"
27- loaderVersion = " 1.1.0-alpha.53"
32+ loom {
33+ runConfigs.all {
34+ ideConfigGenerated(stonecutter.current.isActive)
35+ runDir = " ../../run"
36+ }
2837
29- usePolyMixin = true
30- polyMixinVersion = " 0.8.4+build.7 "
38+ runConfigs.remove(runConfigs[ " server " ])
39+ }
3140
32- applyLoaderTweaker = true
41+ dependencies {
42+ minecraft(" com.mojang:minecraft:$mcversion " )
43+ compileOnly(" com.mojang:datafixerupper:4.0.26" )
44+ mappings(loom.officialMojangMappings())
3345
34- for (module in arrayOf(" commands" , " config" , " config-impl" , " events" , " internal" , " hud" , " ui" , " utils" )) {
35- + module
36- }
46+ modImplementation(" net.fabricmc:fabric-loader:${property(" loader_version" )} " )
47+ modImplementation(" maven.modrinth:notenoughcrashes:${property(" nec_version" )} +$mcversion -fabric" )
48+ implementation(annotationProcessor(" com.github.bawnorton.mixinsquared:mixinsquared-common:0.3.3" )!! )
49+ implementation(" gs.mclo:api:3.0.1" )
50+
51+ modImplementation(" org.polyfrost.oneconfig:$mcversion -fabric:1.0.0-alpha.182" )
52+ for (module in arrayOf(" config" , " config-impl" , " internal" , " ui" )) {
53+ implementation(" org.polyfrost.oneconfig:$module :$oneconfigversion " )
3754 }
55+ }
3856
39- useMixinExtras(" 0.5.0" )
57+ bloom {
58+ replacement(" @MOD_ID@" , modid!! )
59+ replacement(" @MOD_NAME@" , modname!! )
60+ replacement(" @MOD_VERSION@" , modversion!! )
61+ }
4062
41- useProperty(" mixin.debug.export" , " true" , GameSide .BOTH )
63+ tasks.processResources {
64+ val props = mapOf (
65+ " mod_id" to modid,
66+ " mod_name" to modname,
67+ " mod_version" to modversion,
68+ " mc_version" to mcversion,
69+ " loader_version" to providers.gradleProperty(" loader_version" ).get()
70+ )
4271
43- // Turns off the server-side run configs, as we're building a client-sided mod.
44- disableRunConfigs(GameSide .SERVER )
72+ inputs.properties(props)
4573
46- // Defines the name of the Mixin refmap, which is used to map the Mixin classes to the obfuscated Minecraft classes.
47- if (! mcData.isNeoForge) {
48- useMixinRefMap(modData.id)
74+ filesMatching(" fabric.mod.json" ) {
75+ expand(props)
4976 }
77+ }
5078
51- if (mcData.isForge) {
52- // Configures the Mixin tweaker if we are building for Forge.
53- useForgeMixin(modData.id)
79+ tasks.build {
80+ doLast {
81+ val sourceFile = rootProject.projectDir.resolve(" versions/${project.name} /build/libs/crashpatch.jar" )
82+ val targetFile = rootProject.projectDir.resolve(" build/libs/crashpatch-${stonecutter.current.version} .jar" )
83+ targetFile.parentFile.mkdirs()
84+ targetFile.writeBytes(sourceFile.readBytes())
5485 }
5586}
5687
57- repositories {
58- maven(" https://api.modrinth.com/maven" ) {
59- content { includeGroup(" maven.modrinth" ) }
60- }
61- maven(" https://maven.bawnorton.com/releases" ) {
62- content { includeGroup(" com.github.bawnorton.mixinsquared" ) }
63- }
88+ tasks.withType<JavaCompile >().configureEach {
89+ options.release.set(21 )
6490}
6591
66- dependencies {
67- compileOnly(" com.mojang:datafixerupper:4.0.26" )
68- implementation(includeOrShade(" gs.mclo:api:3.0.1" )!! )
69- includeOrShade(implementation(annotationProcessor(" com.github.bawnorton.mixinsquared:mixinsquared-common:0.3.3" )!! )!! )
70- if (mcData.version >= MinecraftVersions .VERSION_1_16 ) {
71- includeOrShade(implementation(" com.github.bawnorton.mixinsquared:mixinsquared-${mcData.loader} :0.3.3" )!! )
72- data class CompatDependency (
73- val forge : String ,
74- val fabric : String ,
75- val neoforge : String
76- )
77-
78- fun DependencyHandlerScope.modImplementationCompat (notation : CompatDependency ? ) {
79- notation?.let {
80- when {
81- mcData.isNeoForge -> modImplementation(it.neoforge)
82- mcData.isForge -> modImplementation(it.forge)
83- mcData.isFabric -> modImplementation(it.fabric)
84- else -> error(" Unsupported loader type: ${mcData.loader} " )
85- }
86- }
87- }
92+ tasks.withType<KotlinCompile >().configureEach {
93+ compilerOptions.jvmTarget.set(JvmTarget .JVM_21 )
94+ }
8895
89- fun nec (mcVersion : String , modVersion : String ) =
90- mcVersion to CompatDependency (
91- fabric = " maven.modrinth:notenoughcrashes:$modVersion +$mcVersion -fabric" ,
92- forge = " maven.modrinth:notenoughcrashes:$modVersion +$mcVersion -forge" ,
93- neoforge = " maven.modrinth:notenoughcrashes:$modVersion +$mcVersion -neoforge"
94- )
95-
96- val nec = mapOf (
97- nec(" 1.16.5" , " 4.1.4" ),
98- nec(" 1.20.1" , " 4.4.9" ),
99- nec(" 1.20.4" , " 4.4.7" ),
100- nec(" 1.21.1" , " 4.4.9" ),
101- nec(" 1.21.4" , " 4.4.8" ),
102- nec(" 1.21.5" , " 4.4.9" ),
103- nec(" 1.21.8" , " 4.4.9" ),
104- )
105-
106- modImplementationCompat(nec[mcData.version.toString()])
107- }
96+ java {
97+ withSourcesJar()
98+ sourceCompatibility = JavaVersion .VERSION_21
99+ targetCompatibility = JavaVersion .VERSION_21
108100}
109101
110- tasks {
111- jar {
112- duplicatesStrategy = DuplicatesStrategy .EXCLUDE
102+ tasks.jar {
103+ inputs.property(" archivesName" , base.archivesName)
104+
105+ from(" LICENSE" ) {
106+ rename { " ${it} _${inputs.properties[" archivesName" ]} " }
113107 }
108+ }
109+
110+ fun <T > optionalProp (property : String , block : (String ) -> T ? ): T ? =
111+ findProperty(property)?.toString()?.takeUnless { it.isBlank() }?.let (block)
112+
113+ val modrinthId = findProperty(" publish.modrinth" )?.toString()?.takeIf { it.isNotBlank() }
114+
115+ // make sure modrinth.token is set in your user gradle properties
116+ publishMods {
117+ file = project.tasks.remapJar.get().archiveFile
118+
119+ displayName = modversion.toString()
120+ version = " v$modversion "
121+ changelog = project.rootProject.file(" CHANGELOG.md" ).takeIf { it.exists() }?.readText() ? : " No changelog provided."
122+ type = ALPHA
123+
124+ modLoaders.add(" fabric" )
125+
126+ dryRun = modrinthId == null
127+
128+ if (modrinthId != null ) {
129+ modrinth {
130+ projectId = property(" publish.modrinth" ).toString()
131+ accessToken = findProperty(" modrinth.token" ).toString()
132+
133+ minecraftVersions.add(mcversion)
114134
115- remapJar {
116- manifest {
117- attributes(mapOf (
118- " MixinConfigs" to " mixins.crashpatch.init.json,mixins.crashpatch.json" ,
119- ))
135+ requires(" oneconfig" )
120136 }
121137 }
122138}
0 commit comments