11plugins {
2- id( " fabric- loom" ) version " 1.10-SNAPSHOT "
2+ alias(libs.plugins. fabric. loom)
33 id(" maven-publish" )
4- id(" com.gradleup.shadow" ) version " 9.0.0-beta11"
54}
65
76base {
87 archivesName = properties[" archives_base_name" ] as String
98 group = properties[" maven_group" ] as String
109
11- val suffix = if (project.hasProperty(" build_number" )) {
12- project.findProperty(" build_number" )
13- } else {
14- " local"
15- }
16-
17- version = properties[" minecraft_version" ] as String + " -" + suffix
10+ val suffix = providers.gradleProperty(" build_number" ).getOrElse(" local" )
11+ version = " ${libs.versions.minecraft.get()} -$suffix "
1812}
1913
2014repositories {
@@ -50,7 +44,7 @@ repositories {
5044}
5145
5246val modInclude: Configuration by configurations.creating
53- val library : Configuration by configurations.creating
47+ val jij : Configuration by configurations.creating
5448
5549configurations {
5650 // include mods
@@ -61,71 +55,109 @@ configurations {
6155 extendsFrom(modInclude)
6256 }
6357
64- // include libraries
58+ // include libraries (jar-in-jar)
6559 implementation.configure {
66- extendsFrom(library )
60+ extendsFrom(jij )
6761 }
68- shadow .configure {
69- extendsFrom(library )
62+ include .configure {
63+ extendsFrom(jij )
7064 }
7165}
7266
7367dependencies {
7468 // Fabric
75- minecraft(" com.mojang: minecraft: ${properties[ " minecraft_version " ] as String } " )
76- mappings(" net.fabricmc: yarn: ${properties[ " yarn_mappings " ] as String } :v2 " )
77- modImplementation(" net.fabricmc: fabric- loader: ${properties[ " loader_version " ] as String } " )
69+ minecraft(libs. minecraft)
70+ mappings(variantOf(libs. yarn) { classifier( " v2 " ) } )
71+ modImplementation(libs. fabric. loader)
7872
79- modInclude(fabricApi.module(" fabric-api-base" , properties[" fapi_version" ] as String ))
80- modInclude(fabricApi.module(" fabric-resource-loader-v0" , properties[" fapi_version" ] as String ))
73+ val fapiVersion = libs.versions.fabric.api.get()
74+ modInclude(fabricApi.module(" fabric-api-base" , fapiVersion))
75+ modInclude(fabricApi.module(" fabric-resource-loader-v1" , fapiVersion))
8176
8277 // Compat fixes
83- modCompileOnly(fabricApi.module(" fabric-renderer-indigo" , properties[" fapi_version" ] as String ))
84- modCompileOnly(" maven.modrinth:sodium:${properties[" sodium_version" ] as String } " ) { isTransitive = false }
85- modCompileOnly(" maven.modrinth:lithium:${properties[" lithium_version" ] as String } " ) { isTransitive = false }
86- modCompileOnly(" maven.modrinth:iris:${properties[" iris_version" ] as String } " ) { isTransitive = false }
87- modCompileOnly(" com.viaversion:viafabricplus:${properties[" viafabricplus_version" ] as String } " ) { isTransitive = false }
88- modCompileOnly(" com.viaversion:viafabricplus-api:${properties[" viafabricplus_version" ] as String } " ) { isTransitive = false }
89-
90- // Baritone (https://github.com/MeteorDevelopment/baritone)
91- modCompileOnly(" meteordevelopment:baritone:${properties[" baritone_version" ] as String } -SNAPSHOT" )
92- // ModMenu (https://github.com/TerraformersMC/ModMenu)
93- modCompileOnly(" com.terraformersmc:modmenu:${properties[" modmenu_version" ] as String } " )
94-
95- // Libraries
96- library(" meteordevelopment:orbit:${properties[" orbit_version" ] as String } " )
97- library(" org.meteordev:starscript:${properties[" starscript_version" ] as String } " )
98- library(" meteordevelopment:discord-ipc:${properties[" discordipc_version" ] as String } " )
99- library(" org.reflections:reflections:${properties[" reflections_version" ] as String } " )
100- library(" io.netty:netty-handler-proxy:${properties[" netty_version" ] as String } " ) { isTransitive = false }
101- library(" io.netty:netty-codec-socks:${properties[" netty_version" ] as String } " ) { isTransitive = false }
102- library(" de.florianmichael:WaybackAuthLib:${properties[" waybackauthlib_version" ] as String } " )
103-
104- // Launch sub project
105- shadow(project(" :launch" ))
78+ modCompileOnly(fabricApi.module(" fabric-renderer-indigo" , fapiVersion))
79+ modCompileOnly(libs.sodium) { isTransitive = false }
80+ modCompileOnly(libs.lithium) { isTransitive = false }
81+ modCompileOnly(libs.iris) { isTransitive = false }
82+ modCompileOnly(libs.viafabricplus) { isTransitive = false }
83+ modCompileOnly(libs.viafabricplus.api) { isTransitive = false }
84+
85+ modCompileOnly(libs.baritone)
86+ modCompileOnly(libs.modmenu)
87+
88+ // Libraries (JAR-in-JAR)
89+ jij(libs.orbit)
90+ jij(libs.starscript)
91+ jij(libs.discord.ipc)
92+ jij(libs.reflections)
93+ jij(libs.netty.handler.proxy) { isTransitive = false }
94+ jij(libs.netty.codec.socks) { isTransitive = false }
95+ jij(libs.waybackauthlib)
10696}
10797
108- loom {
109- accessWidenerPath = file(" src/main/resources/meteor-client.accesswidener" )
98+ sourceSets {
99+ val launcher by creating {
100+ java {
101+ srcDir(" src/launcher/java" )
102+ }
103+ }
104+ }
105+
106+ java {
107+ sourceCompatibility = JavaVersion .VERSION_21
108+ targetCompatibility = JavaVersion .VERSION_21
109+
110+ if (System .getenv(" CI" )?.toBoolean() == true ) {
111+ withSourcesJar()
112+ withJavadocJar()
113+ }
110114}
111115
116+ // Handle transitive dependencies for jar-in-jar
117+ // Based on implementation from BaseProject by FlorianMichael/EnZaXD
118+ // Source: https://github.com/FlorianMichael/BaseProject/blob/main/src/main/kotlin/de/florianmichael/baseproject/Fabric.kt
119+ // Licensed under Apache License 2.0
112120afterEvaluate {
113- tasks.migrateMappings.configure {
114- outputDir.set(project.file(" src/main/java" ))
121+ val jijConfig = configurations.findByName(" jij" ) ? : return @afterEvaluate
122+
123+ // Dependencies to exclude from jar-in-jar
124+ val excluded = setOf (
125+ " org.slf4j" , // Logging provided by Minecraft
126+ " jsr305" // Compile time annotations only
127+ )
128+
129+ jijConfig.incoming.resolutionResult.allDependencies.forEach { dep ->
130+ val requested = dep.requested.displayName
131+
132+ if (excluded.any { requested.contains(it) }) return @forEach
133+
134+ val compileOnlyDep = dependencies.create(requested) {
135+ isTransitive = false
136+ }
137+
138+ val implDep = dependencies.create(compileOnlyDep)
139+
140+ dependencies.add(" compileOnlyApi" , compileOnlyDep)
141+ dependencies.add(" implementation" , implDep)
142+ dependencies.add(" include" , compileOnlyDep)
115143 }
116144}
117145
146+ loom {
147+ accessWidenerPath = file(" src/main/resources/meteor-client.accesswidener" )
148+ }
149+
118150tasks {
119151 processResources {
120- val buildNumber = project.findProperty (" build_number" )?.toString() ? : " "
121- val commit = project.findProperty (" commit" )?.toString() ? : " "
152+ val buildNumber = providers.gradleProperty (" build_number" ).getOrElse( " " )
153+ val commit = providers.gradleProperty (" commit" ).getOrElse( " " )
122154
123155 val propertyMap = mapOf (
124156 " version" to project.version,
125157 " build_number" to buildNumber,
126158 " commit" to commit,
127- " minecraft_version" to project.property( " minecraft_version " ),
128- " loader_version" to project.property( " loader_version " )
159+ " minecraft_version" to libs.versions.minecraft.get( ),
160+ " loader_version" to libs.versions.fabric.loader.get( )
129161 )
130162
131163 inputs.properties(propertyMap)
@@ -134,53 +166,35 @@ tasks {
134166 }
135167 }
136168
169+ // Compile launcher with Java 8 for backwards compatibility
170+ named<JavaCompile >(" compileLauncherJava" ).configure {
171+ sourceCompatibility = JavaVersion .VERSION_1_8 .toString()
172+ targetCompatibility = JavaVersion .VERSION_1_8 .toString()
173+ options.compilerArgs.add(" -Xlint:-options" )
174+ }
175+
137176 jar {
138177 inputs.property(" archivesName" , project.base.archivesName.get())
139178
140179 from(" LICENSE" ) {
141180 rename { " ${it} _${inputs.properties[" archivesName" ]} " }
142181 }
143182
183+ // Include launcher classes
184+ from(sourceSets[" launcher" ].output)
185+
144186 manifest {
145187 attributes[" Main-Class" ] = " meteordevelopment.meteorclient.Main"
146188 }
147189 }
148190
149- java {
150- sourceCompatibility = JavaVersion .VERSION_21
151- targetCompatibility = JavaVersion .VERSION_21
152-
153- if (System .getenv(" CI" )?.toBoolean() == true ) {
154- withSourcesJar()
155- withJavadocJar()
156- }
157- }
158-
159- withType<JavaCompile > {
160- options.release = 21
161- options.compilerArgs.add(" -Xlint:deprecation" )
162- options.compilerArgs.add(" -Xlint:unchecked" )
163- }
164-
165- shadowJar {
166- configurations = listOf (project.configurations.shadow.get())
167-
168- inputs.property(" archivesName" , project.base.archivesName.get())
169-
170- from(" LICENSE" ) {
171- rename { " ${it} _${inputs.properties[" archivesName" ]} " }
172- }
173-
174- dependencies {
175- exclude {
176- it.moduleGroup == " org.slf4j"
177- }
178- }
179- }
180-
181- remapJar {
182- dependsOn(shadowJar)
183- inputFile.set(shadowJar.get().archiveFile)
191+ withType<JavaCompile >().configureEach {
192+ options.compilerArgs.addAll(
193+ listOf (
194+ " -Xlint:deprecation" ,
195+ " -Xlint:unchecked"
196+ )
197+ )
184198 }
185199
186200 javadoc {
@@ -204,7 +218,7 @@ publishing {
204218 from(components[" java" ])
205219 artifactId = " meteor-client"
206220
207- version = properties[ " minecraft_version " ] as String + " -SNAPSHOT"
221+ version = " ${libs.versions.minecraft.get()} -SNAPSHOT"
208222 }
209223 }
210224
0 commit comments