Skip to content

Commit

Permalink
Migrate buildscript to Kotlin DSL
Browse files Browse the repository at this point in the history
The constants used for configuring the build
dependencies are now defined in `build.gradle.kts`.
  • Loading branch information
jellysquid3 committed Jan 28, 2024
1 parent 4f0b7bd commit c3b4898
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 164 deletions.
138 changes: 0 additions & 138 deletions build.gradle

This file was deleted.

136 changes: 136 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
object Constants {
// https://fabricmc.net/develop/
const val MINECRAFT_VERSION: String = "1.20.3"
const val YARN_VERSION: String = "1.20.3+build.1"
const val FABRIC_LOADER_VERSION: String = "0.15.0"
const val FABRIC_API_VERSION: String = "0.91.1+1.20.3"

// https://semver.org/
const val MOD_VERSION: String = "0.5.6"
}

plugins {
// Unlike most projects, we choose to pin the specific version of Loom.
// This prevents a lot of issues where the build script can fail randomly because the Fabric Maven server
// is not reachable for some reason, and it makes builds much more reproducible. Observation also shows that it
// really helps to improve startup times on slow connections.
id("fabric-loom") version "1.5.7"
}

base {
archivesName = "sodium-fabric"

group = "me.jellysquid.mods"
version = createVersionString()
}

loom {
accessWidenerPath = file("src/main/resources/sodium.accesswidener")
}

java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

sourceSets {
val main = getByName("main")
val api = create("api")
val desktop = create("desktop")

api.apply {
java {
compileClasspath += main.compileClasspath
}
}

desktop.apply {
java {
srcDir("src/desktop/java")
}
}

main.apply {
java {
compileClasspath += api.output
runtimeClasspath += api.output
}
}
}

dependencies {
minecraft(group = "com.mojang", name = "minecraft", version = Constants.MINECRAFT_VERSION)
mappings(group = "net.fabricmc", name = "yarn", version = Constants.YARN_VERSION, classifier = "v2")
modImplementation(group = "net.fabricmc", name = "fabric-loader", version = Constants.FABRIC_LOADER_VERSION)

fun addEmbeddedFabricModule(name: String) {
val module = fabricApi.module(name, Constants.FABRIC_API_VERSION)
modImplementation(module)
include(module)
}

// Fabric API modules
addEmbeddedFabricModule("fabric-api-base")
addEmbeddedFabricModule("fabric-block-view-api-v2")
addEmbeddedFabricModule("fabric-rendering-fluids-v1")
addEmbeddedFabricModule("fabric-rendering-data-attachment-v1")
addEmbeddedFabricModule("fabric-resource-loader-v0")
}

tasks {
jar {
from("${rootProject.projectDir}/COPYING")
from("${rootProject.projectDir}/COPYING.LESSER")

val api = sourceSets.getByName("api")
from(api.output.classesDirs)
from(api.output.resourcesDir)

val desktop = sourceSets.getByName("desktop")
from(desktop.output.classesDirs)
from(desktop.output.resourcesDir)

manifest.attributes["Main-Class"] = "net.caffeinemc.mods.sodium.desktop.LaunchWarn"
}

processResources {
inputs.property("version", project.version)

filesMatching("fabric.mod.json") {
expand(mapOf("version" to project.version))
}
}
}

// ensure that the encoding is set to UTF-8, no matter what the system default is
// this fixes some edge cases with special characters not displaying correctly
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
}

fun createVersionString(): String {
val builder = StringBuilder()

val isReleaseBuild = project.hasProperty("build.release")
val buildId = System.getenv("GITHUB_RUN_NUMBER")

if (isReleaseBuild) {
builder.append(Constants.MOD_VERSION)
} else {
builder.append(Constants.MOD_VERSION.substringBefore('-'))
builder.append("-snapshot")
}

builder.append("+mc").append(Constants.MINECRAFT_VERSION)

if (!isReleaseBuild) {
if (buildId != null) {
builder.append("-build.${buildId}")
} else {
builder.append("-local")
}
}

return builder.toString()
}
15 changes: 1 addition & 14 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,15 +1,2 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx2G

# Fabric Properties
# check these on https://fabricmc.net/develop/
minecraft_version=1.20.3
yarn_mappings=1.20.3+build.1
loader_version=0.15.0
fabric_version=0.91.1+1.20.3

# Mod Properties
mod_version=0.5.6
maven_group=me.jellysquid.mods
archives_base_name=sodium-fabric
main_class=net.caffeinemc.mods.sodium.desktop.LaunchWarn
org.gradle.jvmargs=-Xmx2G
12 changes: 0 additions & 12 deletions settings.gradle

This file was deleted.

12 changes: 12 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
rootProject.name = "sodium"

pluginManagement {
repositories {
maven("https://maven.fabricmc.net/") {
name = "Fabric"
}

mavenCentral()
gradlePluginPortal()
}
}

0 comments on commit c3b4898

Please sign in to comment.