Knockdowns-Legacy/build.gradle
2023-04-24 15:42:45 +01:00

201 lines
6.2 KiB
Groovy

import com.gtnewhorizons.retrofuturagradle.mcp.ReobfuscatedJar
import org.jetbrains.gradle.ext.Gradle
plugins {
id("java")
id("java-library")
id("maven-publish")
id("org.jetbrains.gradle.plugin.idea-ext") version "1.1.7"
id("eclipse")
id("com.gtnewhorizons.retrofuturagradle") version "1.3.3"
id("com.matthewprenger.cursegradle") version "1.4.0"
}
version = project.mod_version
group = project.maven_group
archivesBaseName = project.archives_base_name
// Set the toolchain version to decouple the Java we run Gradle with from the Java used to compile and run the mod
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(8))
// Azul covers the most platforms for Java 8 toolchains, crucially including MacOS arm64
vendor.set(org.gradle.jvm.toolchain.JvmVendorSpec.AZUL)
}
// Generate sources and javadocs jars when building and publishing
withSourcesJar()
withJavadocJar()
}
tasks.withType(JavaCompile).configureEach {
options.encoding = "UTF-8"
}
configurations {
embed
implementation.extendsFrom(embed)
}
minecraft {
mcVersion = '1.12.2'
def args = ["-ea:${project.group}"]
if (project.use_coremod.toBoolean()) {
args << '-Dfml.coreMods.load=' + coremod_plugin_class_name
}
if (project.use_mixins.toBoolean()) {
args << '-Dmixin.hotSwap=true'
args << '-Dmixin.checks.interfaces=true'
args << '-Dmixin.debug.export=true'
}
extraRunJvmArguments.addAll(args)
injectedTags.put("VERSION", project.version)
}
// Generate a my.project.Tags class with the version number as a field
tasks.injectTags.configure {
outputClassName.set("${project.group}.Tags")
}
repositories {
maven {
url = 'https://maven.cleanroommc.com'
}
maven { url = "https://repo.spongepowered.org/maven" }
//maven { url "https://maven.mcmoddev.com/" }
maven {
url "https://cursemaven.com"
content {
includeGroup "curse.maven"
}
}
mavenLocal() // Must be last for caching to work
}
dependencies {
if (project.use_assetmover.toBoolean()) {
implementation 'com.cleanroommc:assetmover:2.0'
}
if (project.use_mixins.toBoolean()) {
implementation 'zone.rong:mixinbooter:7.0'
}
// Example deobf dependency
// compileOnly rfg.deobf("curse.maven:endercore-231868:2972849:")
if (project.use_mixins.toBoolean()) {
api ("org.spongepowered:mixin:0.8.3") {transitive = false}
annotationProcessor('org.ow2.asm:asm-debug-all:5.2')
annotationProcessor('com.google.guava:guava:24.1.1-jre')
annotationProcessor('com.google.code.gson:gson:2.8.6')
annotationProcessor ("org.spongepowered:mixin:0.8.3") {transitive = false}
}
}
def mixinConfigRefMap = 'mixins.' + project.archives_base_name + '.refmap.json'
def mixinTmpDir = buildDir.path + File.separator + 'tmp' + File.separator + 'mixins'
def refMap = "${mixinTmpDir}" + File.separator + mixinConfigRefMap
def mixinSrg = "${mixinTmpDir}" + File.separator + "mixins.srg"
if (project.use_mixins.toBoolean()) {
tasks.named("reobfJar", ReobfuscatedJar).configure {
extraSrgFiles.from(mixinSrg)
}
tasks.named("compileJava", JavaCompile).configure {
doFirst {
new File(mixinTmpDir).mkdirs()
}
options.compilerArgs += [
"-AreobfSrgFile=${tasks.reobfJar.srg.get().asFile}",
"-AoutSrgFile=${mixinSrg}",
"-AoutRefMapFile=${refMap}",
]
}
}
if (project.use_access_transformer.toBoolean()) {
for (File at : sourceSets.getByName("main").resources.files) {
if (at.name.toLowerCase().endsWith("_at.cfg")) {
tasks.deobfuscateMergedJarToSrg.accessTransformerFiles.from(at)
tasks.srgifyBinpatchedJar.accessTransformerFiles.from(at)
}
}
}
processResources {
// this will ensure that this task is redone when the versions change.
inputs.property 'version', project.version
inputs.property 'mcversion', project.minecraft.version
// replace stuff in mcmod.info, nothing else
filesMatching(['mcmod.info', 'pack.mcmeta']) { fcd ->
include 'mcmod.info'
// replace version and mcversion
fcd.expand (
'version': project.version,
'mcversion': project.minecraft.version
)
}
if (project.use_access_transformer.toBoolean()) {
rename '(.+_at.cfg)', 'META-INF/$1' // Access Transformers
}
if (project.use_mixins.toBoolean()) {
// Embed mixin refmap
from refMap
dependsOn("compileJava")
}
}
jar {
manifest {
def attribute_map = [:]
if (project.use_coremod.toBoolean()) {
attribute_map['FMLCorePlugin'] = project.coremod_plugin_class_name
if (project.include_mod.toBoolean()) {
attribute_map['FMLCorePluginContainsFMLMod'] = true
attribute_map['ForceLoadAsMod'] = project.gradle.startParameter.taskNames[0] == "build"
}
}
if (project.use_access_transformer.toBoolean()) {
attribute_map['FMLAT'] = project.archives_base_name + '_at.cfg'
}
attributes(attribute_map)
}
// Add all embedded dependencies into the jar
from(provider{ configurations.embed.collect {it.isDirectory() ? it : zipTree(it)} })
}
idea {
module { inheritOutputDirs = true }
project { settings {
runConfigurations {
"1. Run Client"(Gradle) {
taskNames = ["runClient"]
}
"2. Run Server"(Gradle) {
taskNames = ["runServer"]
}
"3. Run Obfuscated Client"(Gradle) {
taskNames = ["runObfClient"]
}
"4. Run Obfuscated Server"(Gradle) {
taskNames = ["runObfServer"]
}
}
compiler.javac {
afterEvaluate {
javacAdditionalOptions = "-encoding utf8"
moduleJavacAdditionalOptions = [
(project.name + ".main"): tasks.compileJava.options.compilerArgs.collect { '"' + it + '"' }.join(' ')
]
}
}
}}
}
tasks.named("processIdeaSettings").configure {
dependsOn("injectTags")
}