Created
May 20, 2021 03:47
-
-
Save ChampionAsh5357/9aedc4a3411b12b6a8c627b5454a7f8a to your computer and use it in GitHub Desktop.
Kotlin Buildscript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile | |
import net.minecraftforge.gradle.common.util.RunConfig | |
import net.minecraftforge.gradle.userdev.UserDevExtension | |
import net.minecraftforge.gradle.userdev.DependencyManagementExtension | |
import java.time.Instant | |
import java.time.format.DateTimeFormatter | |
// Attach plugins | |
plugins { | |
// The ForgeGradle Plugin, necessary to create the userdev environment and build mods | |
id("net.minecraftforge.gradle") version "4.1.+" | |
// Language Specific Plugins go here | |
// Language: Plugin: | |
// Java 'java-library' | |
// Kotlin 'org.jetbrains.kotlin.jvm' (needs version identifier) | |
// Scala 'scala' | |
// Groovy 'groovy' | |
kotlin("jvm") version "latest.release" | |
} | |
// Load Properties | |
val userName: String by project | |
val userGroup: String by project | |
val minecraftVersion: String by project | |
val forgeVersion: String by project | |
val mappingsType: String by project | |
val mappingsVersion: String by project | |
val modId: String by project | |
val modName: String by project | |
val modDesc: String by project | |
val modTransformer: String by project | |
val modSpecVer: String by project | |
val modImplVer: String by project | |
// Standard Project Information | |
version = "$minecraftVersion-$modSpecVer.$modImplVer" | |
group = userGroup | |
base.archivesBaseName = modId | |
// Sets the toolchain to compile against OpenJDK 8 | |
java.toolchain { | |
languageVersion.set(JavaLanguageVersion.of(8)) | |
vendor.set(JvmVendorSpec.ADOPTOPENJDK) | |
} | |
// Set Kotlin to compile on latest with Java 8 target | |
tasks.withType<KotlinCompile>().configureEach { | |
kotlinOptions { | |
apiVersion = "1.5" | |
languageVersion = "1.5" | |
jvmTarget = "1.8" | |
} | |
} | |
// Add generated source set and attach to main source set | |
sourceSets { | |
create("generated") | |
main.get().resources { | |
srcDirs(sourceSets["generated"].resources.srcDirs) | |
exclude(".cache/") | |
} | |
} | |
configure<UserDevExtension> { | |
// The mappings can be changed at any time, and must be in the following format: | |
// Channel: Version: | |
// snapshot YYYYMMDD Snapshot are built nightly | |
// stable # Stables are built at the discretion of the MCP team | |
// official MCVersion Official field/method names from Mojang mapping files | |
// | |
// You must be aware of the Mojang license when using the 'official' mappings | |
// See more information here: https://github.com/MinecraftForge/MCPConfig/blob/master/Mojang.md | |
// | |
// Use non-default mappings at your own risk. they may not always work | |
// Simply re-run your setup task after changing the mappings to update your workspace | |
mappings(mappingsType, mappingsVersion) | |
// Exposes fields, methods, constructors, and classes for use within the mod | |
// Set mod_transformer to 'true' within gradle.properties to enable | |
if (modTransformer.toBoolean()) | |
accessTransformer(file("src/main/resources/META-INF/accesstransformer.cfg")) | |
// Default run configurations | |
// These can be tweaked, removed, or duplicated as needed | |
runs(closureOf<NamedDomainObjectContainer<RunConfig>> { | |
// Client run configuration | |
create("client") { | |
// Directory for the project to run in | |
workingDirectory(file("run/client")) | |
// Set the console logging level | |
property("forge.logging.console.level", "debug") | |
// Attach the sources to the run | |
mods.create(modId).source(sourceSets["main"]) | |
} | |
// Server run configuration | |
create("server") { | |
workingDirectory(file("run/server")) | |
property("forge.logging.console.level", "debug") | |
mods.create(modId).source(sourceSets["main"]) | |
} | |
// Data run configuration | |
create("data") { | |
workingDirectory(file("run/data")) | |
property("forge.logging.console.level", "debug") | |
// Specify the modid for data generation, where to output the resulting resource, and where to look for existing resources | |
args("--mod", modId, | |
"--all", | |
"--output", sourceSets["generated"].resources.srcDirs.first(), | |
"--existing", sourceSets["main"].resources.srcDirs.first()) | |
mods.create(modId).source(sourceSets["main"]) | |
} | |
}) | |
} | |
// Repositories to add necessary languages and dependencies | |
repositories { | |
maven { | |
name = "Kotlin For Forge" | |
url = uri("https://thedarkcolour.github.io/KotlinForForge/") | |
} | |
} | |
dependencies { | |
// Include MinecraftForge as a dependency | |
"minecraft"(group = "net.minecraftforge", name = "forge", version = "$minecraftVersion-$forgeVersion") | |
// Include any language specific libraries here | |
// These could either be a mod that has the necessary language libraries and/or the libraries themselves for you to compile against/shade in | |
// It is recommended to use either an existing or separate mod to handle language libraries | |
implementation(project.the<DependencyManagementExtension>().deobf( | |
project.dependencies.create( | |
group = "thedarkcolour", name = "kotlinforforge", version = "1.12.0" | |
)) | |
) | |
implementation(group = "org.jetbrains.kotlin", name = "kotlin-reflect", version = "latest.release") | |
} | |
// Set attributes of the jar | |
tasks.named<Jar>("jar") { | |
// Set manifest information | |
manifest.attributes( | |
"Specification-Title" to modName, | |
"Specification-Vendor" to userName, | |
"Specification-Version" to modSpecVer, | |
"Implementation-Title" to modName, | |
"Implementation-Version" to project.version, | |
"Implementation-Vendor" to userName, | |
"Implementation-Timestamp" to DateTimeFormatter.ISO_INSTANT.format(Instant.now()) | |
) | |
// Reobfuscate the jar file to be used in production | |
finalizedBy("reobfJar") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Gradle Properties | |
org.gradle.jvmargs=-Xmx3G | |
org.gradle.daemon=false | |
# User Information | |
userName = Forge Community Wiki | |
userGroup = uk.gemwire | |
# Minecraft Information | |
minecraftVersion = 1.16.5 | |
# Forge Information | |
forgeVersion = 36.1.23 | |
# Mappings Information | |
mappingsType = official | |
mappingsVersion = 1.16.5 | |
# Mod Information | |
modId = multilingualmodexamples | |
modName = Multilingual Mod Examples | |
modDesc = Different Loaders, Different Languages | |
modTransformer = false | |
modSpecVer = 1.0.0 | |
modImplVer = 0-beta |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.gradle.kotlin.dsl.accessors.runtime.externalModuleDependencyFor | |
// Add External Plugins | |
pluginManagement { | |
// Add MinecraftForge maven to plugin management | |
repositories { | |
maven { url = uri("https://maven.minecraftforge.net") } | |
mavenCentral() | |
} | |
// Resolve ForgeGradle within plugin block | |
resolutionStrategy.eachPlugin { | |
if (requested.id.id == "net.minecraftforge.gradle") | |
useModule(buildscript.dependencies.create(group = requested.id.id, name = "ForgeGradle", version = requested.version)) | |
else if (requested.id.namespace == "org.jetbrains.kotlin") | |
useModule(buildscript.dependencies.create(group = requested.id.namespace!!, name = "kotlin-gradle-plugin", version = requested.version)) | |
} | |
} | |
// Project Name | |
rootProject.name = "MultilingualModExamples-Forge-Kotlin" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment