Skip to content

Commit faff86e

Browse files
build: refactor with Crosby's suggestions
1 parent e68fc13 commit faff86e

1 file changed

Lines changed: 25 additions & 32 deletions

File tree

build.gradle.kts

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,8 @@ base {
77
archivesName = properties["archives_base_name"] as String
88
group = properties["maven_group"] as String
99

10-
val suffix = if (project.hasProperty("build_number")) {
11-
project.findProperty("build_number")
12-
} else {
13-
"local"
14-
}
15-
16-
version = libs.versions.minecraft.get() + "-" + suffix
10+
val suffix = providers.gradleProperty("build_number").getOrElse("local")
11+
version = "${libs.versions.minecraft.get()}-$suffix"
1712
}
1813

1914
repositories {
@@ -69,8 +64,6 @@ configurations {
6964
}
7065
}
7166

72-
sourceSets.create("launcher")
73-
7467
dependencies {
7568
// Fabric
7669
minecraft(libs.minecraft)
@@ -103,15 +96,23 @@ dependencies {
10396
}
10497

10598
sourceSets {
106-
val launcher = getByName("launcher")
107-
108-
launcher.apply {
99+
val launcher by creating {
109100
java {
110101
srcDir("src/launcher/java")
111102
}
112103
}
113104
}
114105

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+
}
114+
}
115+
115116
// Handle transitive dependencies for jar-in-jar
116117
// Based on implementation from BaseProject by FlorianMichael/EnZaXD
117118
// Source: https://github.com/FlorianMichael/BaseProject/blob/main/src/main/kotlin/de/florianmichael/baseproject/Fabric.kt
@@ -148,8 +149,8 @@ loom {
148149

149150
tasks {
150151
processResources {
151-
val buildNumber = project.findProperty("build_number")?.toString() ?: ""
152-
val commit = project.findProperty("commit")?.toString() ?: ""
152+
val buildNumber = providers.gradleProperty("build_number").getOrElse("")
153+
val commit = providers.gradleProperty("commit").getOrElse("")
153154

154155
val propertyMap = mapOf(
155156
"version" to project.version,
@@ -166,7 +167,7 @@ tasks {
166167
}
167168

168169
// Compile launcher with Java 8 for backwards compatibility
169-
getByName<JavaCompile>("compileLauncherJava") {
170+
named<JavaCompile>("compileLauncherJava").configure {
170171
sourceCompatibility = JavaVersion.VERSION_1_8.toString()
171172
targetCompatibility = JavaVersion.VERSION_1_8.toString()
172173
options.compilerArgs.add("-Xlint:-options")
@@ -180,28 +181,20 @@ tasks {
180181
}
181182

182183
// Include launcher classes
183-
val launcher = sourceSets.getByName("launcher")
184-
from(launcher.output.classesDirs)
185-
from(launcher.output.resourcesDir)
184+
from(sourceSets["launcher"].output)
186185

187186
manifest {
188187
attributes["Main-Class"] = "meteordevelopment.meteorclient.Main"
189188
}
190189
}
191190

192-
java {
193-
sourceCompatibility = JavaVersion.VERSION_21
194-
targetCompatibility = JavaVersion.VERSION_21
195-
196-
if (System.getenv("CI")?.toBoolean() == true) {
197-
withSourcesJar()
198-
withJavadocJar()
199-
}
200-
}
201-
202-
withType<JavaCompile> {
203-
options.compilerArgs.add("-Xlint:deprecation")
204-
options.compilerArgs.add("-Xlint:unchecked")
191+
withType<JavaCompile>().configureEach {
192+
options.compilerArgs.addAll(
193+
listOf(
194+
"-Xlint:deprecation",
195+
"-Xlint:unchecked"
196+
)
197+
)
205198
}
206199

207200
javadoc {
@@ -225,7 +218,7 @@ publishing {
225218
from(components["java"])
226219
artifactId = "meteor-client"
227220

228-
version = libs.versions.minecraft.get() + "-SNAPSHOT"
221+
version = "${libs.versions.minecraft.get()}-SNAPSHOT"
229222
}
230223
}
231224

0 commit comments

Comments
 (0)