From 86e0340b82c3df6620ac4a3dcbabdf69ce04fc30 Mon Sep 17 00:00:00 2001 From: naomi Date: Sat, 14 Dec 2024 03:17:12 +0000 Subject: [PATCH] Migrate to Kotlin DSL for buildscripts (#59) LGTM --- build.gradle | 154 ------------------------- build.gradle.kts | 151 ++++++++++++++++++++++++ settings.gradle => settings.gradle.kts | 4 +- 3 files changed, 153 insertions(+), 156 deletions(-) delete mode 100644 build.gradle create mode 100644 build.gradle.kts rename settings.gradle => settings.gradle.kts (59%) diff --git a/build.gradle b/build.gradle deleted file mode 100644 index dc2273ec..00000000 --- a/build.gradle +++ /dev/null @@ -1,154 +0,0 @@ -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - -plugins { - id 'fabric-loom' version "1.9-SNAPSHOT" - id 'maven-publish' - id "org.jetbrains.kotlin.jvm" version "2.1.0" - id 'org.jetbrains.kotlin.plugin.serialization' version '2.1.0' - id "com.google.devtools.ksp" version "2.1.0-1.0.29" -} - -version = project.mod_version -group = project.maven_group - -base { - archivesName = project.archives_base_name -} - -repositories { - maven { - name = "wispForestReleases" - url = uri("https://maven.wispforest.io/releases") - } - maven { - name = "Ladysnake Mods" - url = 'https://maven.ladysnake.org/releases' - } - maven { - name = "Modrinth" - url = "https://api.modrinth.com/maven" - } - maven { - name = "Nucleoid" - url = "https://maven.nucleoid.xyz/" - } - maven { - url = "https://maven.kosmx.dev/" - } - maven { - name = 'ParchmentMC' - url = 'https://maven.parchmentmc.org' - } - maven { - name = 'Quilt' - url = "https://maven.quiltmc.org/repository/release/" - } -} - -loom { - splitEnvironmentSourceSets() - - mods { - "playerex-directors-cut" { - sourceSet sourceSets.main - sourceSet sourceSets.client - } - } -} - -dependencies { - minecraft "com.mojang:minecraft:${project.minecraft_version}" - - mappings loom.layered() { - mappings("org.quiltmc:quilt-mappings:${project.minecraft_version}+build.${project.quilt_mappings_version}:intermediary-v2") - officialMojangMappings() - parchment("org.parchmentmc.data:parchment-${project.parchment_version}@zip") - } - - modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" - - modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" - modImplementation "net.fabricmc:fabric-language-kotlin:${project.fabric_kotlin_version}" - - // in-house - modImplementation("maven.modrinth:data-attributes-directors-cut:${project.data_attributes_version}") - modImplementation include("maven.modrinth:opc-directors-cut:${project.opc_version}") - - // Cardinal Components - modImplementation include("dev.onyxstudios.cardinal-components-api:cardinal-components-base:${project.cardinal_components_version}") - modImplementation include("dev.onyxstudios.cardinal-components-api:cardinal-components-entity:${project.cardinal_components_version}") - modImplementation include("dev.onyxstudios.cardinal-components-api:cardinal-components-chunk:${project.cardinal_components_version}") - modImplementation include("dev.onyxstudios.cardinal-components-api:cardinal-components-level:${project.cardinal_components_version}") - - modImplementation include("maven.modrinth:AdditionalEntityAttributes:${project.additional_entity_attributes_version}") - modImplementation("maven.modrinth:ranged-weapon-api:${project.ranged_weapon_api_version}") - - modImplementation include("io.wispforest:endec:${project.endec_version}") - modImplementation include("io.wispforest.endec:gson:${project.endec_gson_version}") - modImplementation include("io.wispforest.endec:netty:${project.endec_netty_version}") - - // owo - annotationProcessor modImplementation("io.wispforest:owo-lib:${project.owo_version}") - include "io.wispforest:owo-sentinel:${project.owo_version}" - - implementation("com.google.devtools.ksp:symbol-processing-api:${project.ksp_version}") - implementation("com.squareup:kotlinpoet-ksp:${project.kotlinpoet_version}") - ksp("dev.kosmx.kowoconfig:ksp-owo-config:${project.ksp_owo_config_version}") - - modImplementation include("eu.pb4:placeholder-api:${project.placeholder_api_version}") - - implementation include("net.objecthunter:exp4j:${project.exp4j_version}") - - include(implementation(annotationProcessor("io.github.llamalad7:mixinextras-fabric:${project.mixinextras_version}"))) -} - -processResources { - inputs.property "version", project.version - - filesMatching("fabric.mod.json") { - expand "version": project.version - } -} - -tasks.withType(JavaCompile).configureEach { - it.options.release = 17 -} - -tasks.withType(KotlinCompile).configureEach { - kotlinOptions { - jvmTarget = 17 - } -} - -java { - // Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task - // if it is present. - // If you remove this line, sources will not be generated. - withSourcesJar() - - sourceCompatibility = JavaVersion.VERSION_17 - targetCompatibility = JavaVersion.VERSION_17 -} - -jar { - from("LICENSE") { - rename { "${it}_${project.base.archivesName.get()}"} - } -} - -// configure the maven publication -publishing { - publications { - mavenJava(MavenPublication) { - from components.java - } - } - - // See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing. - repositories { - // Add repositories to publish to here. - // Notice: This block does NOT have the same function as the block in the top level. - // The repositories here will be used for publishing your artifact, not for - // retrieving dependencies. - } -} \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 00000000..1cc05985 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,151 @@ +import org.jetbrains.kotlin.gradle.dsl.JvmTarget +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +plugins { + id("fabric-loom") version "1.9-SNAPSHOT" + id("maven-publish") + id("org.jetbrains.kotlin.jvm") version "2.1.0" + id("org.jetbrains.kotlin.plugin.serialization") version "2.1.0" + id("com.google.devtools.ksp") version "2.1.0-1.0.29" +} + +version = "${properties["mod_version"]}" +group = "${properties["maven_group"]}" + +base { + archivesName = "${properties["archives_base_name"]}" +} + +repositories { + maven("https://maven.wispforest.io/releases") { + name = "wispForestReleases" + } + maven("https://maven.ladysnake.org/releases") { + name = "Ladysnake Mods" + } + maven("https://api.modrinth.com/maven") { + name = "Modrinth" + } + maven("https://maven.nucleoid.xyz/") { + name = "Nucleoid" + } + maven("https://maven.kosmx.dev/") { + } + maven("https://maven.parchmentmc.org") { + name = "ParchmentMC" + } + maven("https://maven.quiltmc.org/repository/release/") { + name = "Quilt" + } +} + +loom { + splitEnvironmentSourceSets() + + mods { + register("playerex-directors-cut") { + sourceSet("main") + sourceSet("client") + } + + } +} + +dependencies { + minecraft("com.mojang:minecraft:${properties["minecraft_version"]}") + + mappings(loom.layered() { + mappings("org.quiltmc:quilt-mappings:${properties["minecraft_version"]}+build.${properties["quilt_mappings_version"]}:intermediary-v2") + officialMojangMappings() + parchment("org.parchmentmc.data:parchment-${properties["parchment_version"]}@zip") + }) + + modImplementation("net.fabricmc:fabric-loader:${properties["loader_version"]}") + modImplementation("net.fabricmc.fabric-api:fabric-api:${properties["fabric_version"]}") + modImplementation("net.fabricmc:fabric-language-kotlin:${properties["fabric_kotlin_version"]}") + + // in-house + modImplementation("maven.modrinth:data-attributes-directors-cut:${properties["data_attributes_version"]}") + modImplementation("maven.modrinth:opc-directors-cut:${properties["opc_version"]}")?.let(::include) + + // Cardinal Components + modImplementation("dev.onyxstudios.cardinal-components-api:cardinal-components-base:${properties["cardinal_components_version"]}")?.let(::include) + modImplementation("dev.onyxstudios.cardinal-components-api:cardinal-components-entity:${properties["cardinal_components_version"]}")?.let(::include) + modImplementation("dev.onyxstudios.cardinal-components-api:cardinal-components-chunk:${properties["cardinal_components_version"]}")?.let(::include) + modImplementation("dev.onyxstudios.cardinal-components-api:cardinal-components-level:${properties["cardinal_components_version"]}")?.let(::include) + + modImplementation("maven.modrinth:AdditionalEntityAttributes:${properties["additional_entity_attributes_version"]}")?.let(::include) + modImplementation("maven.modrinth:ranged-weapon-api:${properties["ranged_weapon_api_version"]}") + + modImplementation("io.wispforest:endec:${properties["endec_version"]}")?.let(::include) + modImplementation("io.wispforest.endec:gson:${properties["endec_gson_version"]}")?.let(::include) + modImplementation("io.wispforest.endec:netty:${properties["endec_netty_version"]}")?.let(::include) + + // owo + annotationProcessor("io.wispforest:owo-lib:${properties["owo_version"]}")?.let(::modImplementation) + include("io.wispforest:owo-sentinel:${properties["owo_version"]}") + + implementation("com.google.devtools.ksp:symbol-processing-api:${properties["ksp_version"]}") + implementation("com.squareup:kotlinpoet-ksp:${properties["kotlinpoet_version"]}") + ksp("dev.kosmx.kowoconfig:ksp-owo-config:${properties["ksp_owo_config_version"]}") + + modImplementation("eu.pb4:placeholder-api:${properties["placeholder_api_version"]}")?.let(::include) + + implementation("net.objecthunter:exp4j:${properties["exp4j_version"]}")?.let(::include) + + annotationProcessor("io.github.llamalad7:mixinextras-fabric:${properties["mixinextras_version"]}")?.let { + implementation(it) + include(it) + } +} + +tasks { + processResources { + inputs.property("version", project.version) + + filesMatching("fabric.mod.json") { + expand("version" to project.version) + } + } + + jar { + from("LICENSE") { + rename { "${it}_${project.base.archivesName.get()}"} + } + } + + java { + // Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task + // if it is present. + // If you remove this line, sources will not be generated. + withSourcesJar() + + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 + } + + // configure the maven publication + publishing { + publications { + create("mavenJava") { + artifact(remapJar) { + builtBy(remapJar) + } + artifact(kotlinSourcesJar) { + builtBy(remapSourcesJar) + } + } + } + + repositories {} + } + + withType().configureEach { + compilerOptions { + jvmTarget.set(JvmTarget.JVM_17) + } + } +} + + + diff --git a/settings.gradle b/settings.gradle.kts similarity index 59% rename from settings.gradle rename to settings.gradle.kts index 75c4d726..b540317d 100644 --- a/settings.gradle +++ b/settings.gradle.kts @@ -1,8 +1,8 @@ pluginManagement { repositories { maven { - name = 'Fabric' - url = 'https://maven.fabricmc.net/' + name = "Fabric" + url = uri("https://maven.fabricmc.net/") } mavenCentral() gradlePluginPortal()