diff --git a/build.gradle b/build.gradle deleted file mode 100644 index 9509b1b292..0000000000 --- a/build.gradle +++ /dev/null @@ -1,138 +0,0 @@ -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' -} - -apply plugin: "fabric-loom" - -sourceCompatibility = JavaVersion.VERSION_17 -targetCompatibility = JavaVersion.VERSION_17 - -archivesBaseName = project.archives_base_name -version = createVersionString() -group = project.maven_group - -loom { - mixin { - defaultRefmapName = "mixins.sodium.refmap.json" - } - - accessWidenerPath = file("src/main/resources/sodium.accesswidener") -} - -configurations { - modIncludeImplementation - - include.extendsFrom modIncludeImplementation - modImplementation.extendsFrom modIncludeImplementation -} - -sourceSets { - api { - java { - compileClasspath += main.compileClasspath - } - } - - main { - java { - compileClasspath += api.output - runtimeClasspath += api.output - } - } - - // this source set is should be compiled with Java 8 - desktop { - java { - srcDir "src/desktop/java" - } - } -} - -dependencies { - // Sourced from the gradle.properties file - minecraft "com.mojang:minecraft:${project.minecraft_version}" - mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" - modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" - - // Fabric API - modIncludeImplementation(fabricApi.module("fabric-api-base", project.fabric_version)) - modIncludeImplementation(fabricApi.module("fabric-block-view-api-v2", project.fabric_version)) - modIncludeImplementation(fabricApi.module("fabric-rendering-fluids-v1", project.fabric_version)) - modIncludeImplementation(fabricApi.module("fabric-rendering-data-attachment-v1", project.fabric_version)) - modIncludeImplementation(fabricApi.module("fabric-resource-loader-v0", project.fabric_version)) -} - -jar { - // License files - from "${rootProject.projectDir}/COPYING" - from "${rootProject.projectDir}/COPYING.LESSER" - - // API files - from sourceSets.api.output.classesDirs - from sourceSets.api.output.resourcesDir - - // Desktop application files - from sourceSets.desktop.output.classesDirs - from sourceSets.desktop.output.resourcesDir - - manifest.attributes["Main-Class"] = "${project.main_class}" -} - -processResources { - inputs.property "version", project.version - - filesMatching("fabric.mod.json") { - expand "version": project.version - } -} - -tasks.named('compileDesktopJava') { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 -} - -// 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).configureEach { - options.encoding = "UTF-8" -} - -def createVersionString() { - var builder = new StringBuilder() - - boolean release = project.hasProperty("build.release") - - String build_id = System.getenv("GITHUB_RUN_NUMBER") - String mod_version = project.mod_version as String - - if (release) { - builder.append(mod_version) - } else { - // Strip the existing pre-release version - if (mod_version.contains('-')) { - builder.append(mod_version.substring(0, mod_version.indexOf('-'))) - } else { - builder.append(mod_version) - } - - builder.append("-snapshot") - } - - var minecraft_version = (project.minecraft_version as String) - builder.append("+mc").append(minecraft_version) - - if (!release) { - if (build_id != null) { - builder.append("-build.${build_id}") - } else { - builder.append("-local") - } - } - - return builder.toString() -} \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000000..161226669d --- /dev/null +++ b/build.gradle.kts @@ -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 { + 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() +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 6aecdc7553..35f5ac1b0e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 \ No newline at end of file diff --git a/settings.gradle b/settings.gradle deleted file mode 100644 index 089a224fcc..0000000000 --- a/settings.gradle +++ /dev/null @@ -1,12 +0,0 @@ -pluginManagement { - repositories { - maven { - name = 'Fabric' - url = 'https://maven.fabricmc.net/' - } - mavenCentral() // backup mirror for JCenter's Bintray, which is ordinarily used to resolve Eclipse's JGit - gradlePluginPortal() - } -} - -rootProject.name = "sodium" \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000000..41d020a56f --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,12 @@ +rootProject.name = "sodium" + +pluginManagement { + repositories { + maven("https://maven.fabricmc.net/") { + name = "Fabric" + } + + mavenCentral() + gradlePluginPortal() + } +} \ No newline at end of file