From 14b2b19cb2b6ab1aca400f65b6770199dc0c24ab Mon Sep 17 00:00:00 2001 From: LambdAurora Date: Sat, 12 Oct 2024 22:46:29 +0200 Subject: [PATCH] Convert buildscript to Kotlin. --- build.gradle | 170 ----------------------------------------------- build.gradle.kts | 159 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 159 insertions(+), 170 deletions(-) delete mode 100644 build.gradle create mode 100644 build.gradle.kts diff --git a/build.gradle b/build.gradle deleted file mode 100644 index 7a31ab5..0000000 --- a/build.gradle +++ /dev/null @@ -1,170 +0,0 @@ -plugins { - id 'fabric-loom' version '1.8.+' - id 'dev.yumi.gradle.licenser' version '1.1.+' - id 'java-library' - id 'maven-publish' -} - -import net.fabricmc.loom.task.RemapJarTask - -group = project.maven_group -version = "${project.mod_version}+${getMCVersionString()}" -base.archivesName = project.archives_base_name - -// This field defines the Java version your mod target. -def targetJavaVersion = 21 - -Set modules = [ - 'fabric-api-base', - 'fabric-lifecycle-events-v1', - 'fabric-rendering-v1', - 'fabric-resource-loader-v0', - 'fabric-screen-api-v1', - 'fabric-key-binding-api-v1' -] - -String getMCVersionString() { - return project.minecraft_version -} - -sourceSets { - testmod { - compileClasspath += sourceSets.main.compileClasspath - runtimeClasspath += sourceSets.main.runtimeClasspath - } -} - -repositories { - mavenLocal() - maven { - name 'Quilt' - url 'https://maven.quiltmc.org/repository/release' - } - maven { - name 'TerraformersMC' - url 'https://maven.terraformersmc.com/releases' - } - maven { - name = "QuiltMC" - url = "https://maven.quiltmc.org/repository/release" - } -} - -configurations { - api.extendsFrom libApi -} - -dependencies { - minecraft "com.mojang:minecraft:${project.minecraft_version}" - mappings "org.quiltmc:quilt-mappings:${minecraft_version}+build.${quilt_mappings}:intermediary-v2" - modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" - - modules.stream().map { fabricApi.module(it, project.fabric_api_version) }.forEach { - modImplementation it - } - - modLocalRuntime("com.terraformersmc:modmenu:${project.modmenu_version}") { - transitive = false - } - modLocalRuntime fabricApi.module("fabric-key-binding-api-v1", project.fabric_api_version) - - testmodImplementation sourceSets.main.output -} - -java { - sourceCompatibility = JavaVersion.toVersion(targetJavaVersion) - targetCompatibility = JavaVersion.toVersion(targetJavaVersion) - - withSourcesJar() -} - -tasks.withType(JavaCompile).configureEach { - it.options.encoding = 'UTF-8' - it.options.deprecation(true) - it.options.incremental(true) - it.options.release.set(targetJavaVersion) -} - -processResources { - inputs.property 'version', project.version - - filesMatching('fabric.mod.json') { - expand 'version': project.version - } -} - -jar { - from('LICENSE') { - rename { "${it}_${base.archivesName.get()}" } - } -} - -loom { - runs { - testmodClient { - client() - source(sourceSets.testmod) - } - } -} - -task testmodJar(type: Jar) { - group "build" - from sourceSets.testmod.output - archiveClassifier = "testmod-dev" - destinationDirectory = project.file("build/devlibs") -} - -task remapTestmodJar(type: RemapJarTask, dependsOn: testmodJar) { - group "build" - inputFile = testmodJar.archiveFile - classpath.from sourceSets.testmod.compileClasspath - archiveClassifier = "testmod" -} -build.dependsOn remapTestmodJar - -license { - rule file('HEADER') -} - -// configure the maven publication -publishing { - publications { - mavenJava(MavenPublication) { - from components.java - - pom { - name = 'SpruceUI' - description = 'A Minecraft mod API which adds some GUI utilities.' - } - } - } - - repositories { - mavenLocal() - maven { - name 'BuildDirLocal' - url "${project.layout.buildDirectory.get()}/repo" - } - maven { - name 'GithubPackages' - url 'https://maven.pkg.github.com/LambdAurora/SpruceUI' - credentials { - username = project.findProperty('gpr.user') ?: System.getenv('USERNAME') - password = project.findProperty('gpr.key') ?: System.getenv('TOKEN') - } - } - - def spruceuiMaven = System.getenv('SPRUCEUI_MAVEN') - if (spruceuiMaven) { - maven { - name = 'SpruceUIMaven' - url = uri(spruceuiMaven) - credentials { - username = project.findProperty('gpr.user') ?: System.getenv('MAVEN_USERNAME') - password = project.findProperty('gpr.key') ?: System.getenv('MAVEN_PASSWORD') - } - } - } - } -} diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..c9b17c2 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,159 @@ +import net.fabricmc.loom.task.RemapJarTask + +plugins { + id("fabric-loom").version("1.8.+") + id("dev.yumi.gradle.licenser").version("1.1.+") + `java-library` + `maven-publish` +} + +group = project.property("maven_group") as String +base.archivesName.set(project.property("archives_base_name") as String) + +val mcVersion = project.property("minecraft_version") as String +version = "${project.property("mod_version")}+${mcVersion}" + +val targetJavaVersion = 21 + +val fabricModules = setOf( + "fabric-api-base", + "fabric-lifecycle-events-v1", + "fabric-rendering-v1", + "fabric-resource-loader-v0", + "fabric-screen-api-v1", + "fabric-key-binding-api-v1" +) + +val testmod: SourceSet by sourceSets.creating { + this.compileClasspath += sourceSets.main.get().compileClasspath + this.runtimeClasspath += sourceSets.main.get().runtimeClasspath +} + +repositories { + mavenLocal() + maven { + name = "TerraformersMC" + url = uri("https://maven.terraformersmc.com/releases") + } + maven { + name = "QuiltMC" + url = uri("https://maven.quiltmc.org/repository/release") + } +} + +dependencies { + minecraft("com.mojang:minecraft:${mcVersion}") + mappings("org.quiltmc:quilt-mappings:${mcVersion}+build.${project.property("quilt_mappings")}:intermediary-v2") + modImplementation("net.fabricmc:fabric-loader:${project.property("loader_version")}") + + fabricModules.stream().map { fabricApi.module(it, project.property("fabric_api_version") as String) }.forEach { + modImplementation(it) + } + + modLocalRuntime("com.terraformersmc:modmenu:${project.property("modmenu_version")}") { + isTransitive = false + } + modLocalRuntime(fabricApi.module("fabric-key-binding-api-v1", project.property("fabric_api_version") as String)) + + "testmodImplementation"(sourceSets.main.get().output) +} + +java { + sourceCompatibility = JavaVersion.toVersion(targetJavaVersion) + targetCompatibility = JavaVersion.toVersion(targetJavaVersion) + + withSourcesJar() +} + +tasks.withType().configureEach { + options.encoding = "UTF-8" + options.isDeprecation = true + options.isIncremental = true + options.release.set(targetJavaVersion) +} + +tasks.processResources { + inputs.property("version", project.version) + + filesMatching("fabric.mod.json") { + expand("version" to project.version) + } +} + +tasks.jar { + from("LICENSE") { + rename { "${it}_${base.archivesName.get()}" } + } +} + +loom { + runtimeOnlyLog4j = true + runs { + register("testmodClient") { + client() + source(testmod) + } + } +} + +val testmodJar = tasks.create("testmodJar") { + this.group = "build" + this.from(testmod.output) + this.archiveClassifier = "testmod-dev" + this.destinationDirectory = project.file("build/devlibs") +} + +val remapTestmodJar = tasks.register("remapTestmodJar") { + this.group = "build" + this.dependsOn(testmodJar) + this.inputFile.set(testmodJar.archiveFile) + this.classpath.from(testmod.compileClasspath) + this.archiveClassifier = "testmod" +} +tasks.build.get().dependsOn(remapTestmodJar) + +license { + rule(file("HEADER")) +} + +// Configure the maven publication. +publishing { + publications { + create("mavenJava") { + from(components["java"]) + + pom { + name.set("SpruceUI") + description.set("A Minecraft mod API which adds some GUI utilities.") + } + } + } + + repositories { + mavenLocal() + maven { + name = "BuildDirLocal" + url = uri("${rootProject.layout.buildDirectory.get()}/repo") + } + maven { + name = "GithubPackages" + url = uri("https://maven.pkg.github.com/LambdAurora/SpruceUI") + credentials { + username = (project.findProperty("gpr.user") as? String) ?: System.getenv("USERNAME") + password = (project.findProperty("gpr.key") as? String) ?: System.getenv("TOKEN") + } + } + + val spruceuiMaven = System.getenv("SPRUCEUI_MAVEN") + if (spruceuiMaven != null) { + maven { + name = "SpruceUIMaven" + url = uri(spruceuiMaven) + credentials { + username = (project.findProperty("gpr.user") as? String) ?: System.getenv("MAVEN_USERNAME") + password = (project.findProperty("gpr.key") as? String) ?: System.getenv("MAVEN_PASSWORD") + } + } + } + } +}