/* * Gimbal * Copyright (C) 2024 moonleay * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ import org.jetbrains.gradle.ext.ProjectSettings import org.jetbrains.gradle.ext.TaskTriggersConfig import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { kotlin("jvm") kotlin("plugin.serialization") id("fabric-loom") `maven-publish` eclipse id("org.jetbrains.gradle.plugin.idea-ext") id("com.modrinth.minotaur") version "2.+" } val ver = if ((System.getenv("GITHUB_REF") ?: "local").startsWith("refs/tags/")) System.getenv("GITHUB_REF_NAME") ?: "err" else System.getenv("GIT_SHA_SHORT") ?: "0.0.0" val mavenVersion = ver val modId: String by project val modName: String by project /* * Gimbal version stuff * */ val gimbalProtocolVersion = 3 val mavenGroup: String by project val mavenArtifact: String by project val minecraftVersion = project.ext["minecraft.version"] as String val yarnMappings = project.ext["yarn.version"] as String val fabricLoaderVersion = project.ext["fabric.loader.version"] as String val fabricApiVersion = project.ext["fabric.api.version"] as String val fabricKotlinVersion = project.ext["fabric.kotlin.version"] as String val serializationVersion = project.ext["kotlinx.serialization.version"] as String version = mavenVersion group = mavenGroup project.base.archivesName.set(mavenArtifact) repositories { maven { // Dependency api url = uri("https://oss.sonatype.org/content/repositories/snapshots") } } fabricApi { configureDataGeneration() } dependencies { // To change the versions see the gradle.properties file minecraft("com.mojang:minecraft:$minecraftVersion") mappings("net.fabricmc:yarn:$yarnMappings:v2") modImplementation("net.fabricmc:fabric-loader:$fabricLoaderVersion") modImplementation("net.fabricmc.fabric-api:fabric-api:$fabricApiVersion") modImplementation("net.fabricmc:fabric-language-kotlin:$fabricKotlinVersion") modImplementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$serializationVersion") modApi("me.lucko:fabric-permissions-api:0.2-SNAPSHOT") { exclude(group = "net.fabricmc") } } val targetJavaVersion = 17 val templateSrc = project.rootDir.resolve("src/main/templates") val templateDest = project.buildDir.resolve("generated/templates") val datagenDest = project.rootDir.resolve("src/main/generated") val templateProps = mapOf( "modVersion" to project.version as String, "modId" to modId, "modName" to modName, "protocolVersion" to gimbalProtocolVersion, "minecraftVersion" to minecraftVersion, "fabricLoaderVersion" to fabricLoaderVersion, "fabricKotlinVersion" to fabricKotlinVersion, ) loom { accessWidenerPath.set(file("src/main/resources/$modId.accesswidener")) runs { register("datagenClient") { client() name("Data Generation") vmArg("-Dfabric-api.datagen") vmArg("-Dfabric-api.datagen.output-dir=$datagenDest") vmArg("-Dfabric-api.datagen.modid=$modId") runDir("build/datagen") } } } tasks { withType { filteringCharset = "UTF-8" duplicatesStrategy = DuplicatesStrategy.INCLUDE inputs.properties(templateProps) filesMatching("fabric.mod.json") { expand(templateProps) } } create("generateTemplates") { filteringCharset = "UTF-8" inputs.properties(templateProps) from(templateSrc) expand(templateProps) into(templateDest) } withType { options.encoding = "UTF-8" if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible) { options.release.set(targetJavaVersion) } dependsOn("generateTemplates", "processResources") } withType { kotlinOptions.jvmTarget = targetJavaVersion.toString() dependsOn("generateTemplates", "processResources") } withType { from("LICENSE") { rename { "${it}_${project.base.archivesName.get()}" } } archiveBaseName.set(mavenArtifact) duplicatesStrategy = DuplicatesStrategy.INCLUDE dependsOn("generateTemplates", "processResources") } } java { val javaVersion = JavaVersion.toVersion(targetJavaVersion) if (JavaVersion.current() < javaVersion) { toolchain.languageVersion.set(JavaLanguageVersion.of(targetJavaVersion)) } withSourcesJar() } sourceSets { main { java { srcDir(templateDest) } resources { srcDir(datagenDest) } } } publishing { publications { create("mavenJava") { version = project.version as String artifactId = mavenArtifact from(components["java"]) } } repositories { if (System.getenv("CI") != null) { maven { name = "Codeberg" val repoOwner = System.getenv("GITHUB_REPOSITORY_OWNER") val serverUrl = System.getenv("GITHUB_SERVER_URL") val accessToken = System.getenv("PACKAGE_REPO_KEY") url = uri("$serverUrl/api/packages/$repoOwner/maven") authentication { create("header", HttpHeaderAuthentication::class.java) { credentials(HttpHeaderCredentials::class) { name = "Authorization" value = "token $accessToken" } } } } } } } // build.gradle.kts modrinth { token.set(System.getenv("MODRINTH_TOKEN")) // Remember to have the MODRINTH_TOKEN environment variable set or else this will fail - just make sure it stays private! projectId.set(modId) // This can be the project ID or the slug. Either will work! versionNumber.set(mavenVersion) // You don't need to set this manually. Will fail if Modrinth has this version already versionName.set("$modName $mavenVersion for $minecraftVersion") versionType.set("alpha") // This is the default -- can also be `beta` or `alpha` uploadFile.set(tasks.remapJar) // With Loom, this MUST be set to `remapJar` instead of `jar`! gameVersions.addAll(listOf(project.ext["minecraft.version"] as String)) // Must be an array, even with only one version loaders.add("fabric") // Must also be an array - no need to specify this if you're using Loom or ForgeGradle changelog.set( "Changelog v$mavenVersion\n\nCheckout the changelog [on codeberg](${System.getenv("GITHUB_SERVER_URL") ?: ""}/${ System.getenv( "GITHUB_REPOSITORY" ) ?: "" }/releases/tag/${System.getenv("GITHUB_REF_NAME") ?: ""})" ) dependencies { // A special DSL for creating dependencies // scope.type // The scope can be `required`, `optional`, `incompatible`, or `embedded` // The type can either be `project` or `version` required.project("fabric-api") // Creates a new required dependency on Fabric API required.project("fabric-language-kotlin") } } rootProject.idea.project { this as ExtensionAware configure { this as ExtensionAware configure { afterSync(tasks["generateTemplates"], tasks["processResources"]) } } } rootProject.eclipse.synchronizationTasks("generateTemplates", "processResources")