Skip to content

Commit

Permalink
Remove Arch Plugin and Shadow, clean up buildscript
Browse files Browse the repository at this point in the history
- Disabled refmaps
- Disabled common remapJar
- Replaced shadow with directly including the common code + jij for jankson
- Split off MinifyJsonPlugin from the data generator plugin
  • Loading branch information
Juuxel committed Aug 6, 2024
1 parent acb291a commit 77cde5b
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 95 deletions.
5 changes: 5 additions & 0 deletions build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ gradlePlugin {
implementationClass = "juuxel.adorn.gradle.EmiDataGeneratorPlugin"
}

register("adorn-minify-json") {
id = "adorn-minify-json"
implementationClass = "juuxel.adorn.gradle.MinifyJsonPlugin"
}

register("adorn-service-inline") {
id = "adorn-service-inline"
implementationClass = "juuxel.adorn.gradle.ServiceInlinePlugin"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package juuxel.adorn.gradle;

import juuxel.adorn.gradle.action.MinifyJson;
import juuxel.adorn.gradle.datagen.DataGeneratorExtension;
import juuxel.adorn.gradle.datagen.DeleteDuplicates;
import juuxel.adorn.gradle.datagen.GenerateData;
Expand Down Expand Up @@ -37,8 +36,5 @@ public void apply(Project project) {
main.getResources().srcDir(generatedResources);
main.getResources().exclude(".cache");
});
project.afterEvaluate(p -> {
p.getTasks().named("remapJar", task -> task.doLast(new MinifyJson()));
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package juuxel.adorn.gradle;

import juuxel.adorn.gradle.action.MinifyJson;
import org.gradle.api.Plugin;
import org.gradle.api.Project;

public final class MinifyJsonPlugin implements Plugin<Project> {
@Override
public void apply(Project target) {
target.getTasks().named("remapJar", task -> {
task.doLast(new MinifyJson());
});
}
}
73 changes: 25 additions & 48 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import net.fabricmc.loom.api.LoomGradleExtensionAPI
import net.fabricmc.loom.task.RemapJarTask

Expand All @@ -9,17 +8,9 @@ plugins {
// See https://docs.gradle.org/current/userguide/base_plugin.html.
base

// Set up specific versions of the plugins we're using.
// Note that of all these plugins, only the Architectury plugin needs to be applied.
id("architectury-plugin") version "3.4.+"
// Set up a specific version of Loom. There's no code in the root project,
// so we don't need to apply it here.
id("dev.architectury.loom") version "1.7.+" apply false

id("com.github.johnrengelman.shadow") version "8.1.1" apply false
}

// Set the Minecraft version for Architectury.
architectury {
minecraft = project.property("minecraft-version").toString()
}

// Set up basic Maven artifact metadata, including the project version
Expand Down Expand Up @@ -55,23 +46,23 @@ tasks {
register("classes")
}

// Do the shared set up for the Minecraft subprojects.
// Do the shared setup for the Minecraft subprojects.
subprojects {
apply(plugin = "dev.architectury.loom")
apply(plugin = "architectury-plugin")

// Find the loom extension. Since it's not applied to the root project, we can't access it directly
// by name in this file.
val loom = project.extensions.getByName<LoomGradleExtensionAPI>("loom")
loom.mixin {
useLegacyMixinAp.set(false)
}

// Set Java version.
extensions.configure<JavaPluginExtension> {
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}

architectury {
// Disable Architectury's runtime transformer
// since we don't use it.
compileOnly()
}

// Copy the artifact metadata from the root project.
group = rootProject.group
version = rootProject.version
Expand Down Expand Up @@ -100,6 +91,12 @@ subprojects {
}
}

// For REI.
maven {
name = "shedaniel"
url = uri("https://maven.shedaniel.me")
}

// TerraformersMC maven for Mod Menu and EMI.
maven {
name = "TerraformersMC"
Expand Down Expand Up @@ -128,10 +125,6 @@ subprojects {
// and so the Kotlin accessor method for it isn't generated for this file.
"minecraft"("net.minecraft:minecraft:${rootProject.property("minecraft-version")}")

// Find the loom extension. Since it's not applied to the root project, we can't access it directly
// by name in this file.
val loom = project.extensions.getByName<LoomGradleExtensionAPI>("loom")

// Set up the layered mappings with Yarn and my Menu mappings.
// The average modder would have "mappings"("net.fabricmc:yarn:...") or "mappings"(loom.officialMojangMappings()).
"mappings"(loom.layered {
Expand Down Expand Up @@ -167,50 +160,34 @@ subprojects {
// Set up "platform" subprojects (non-common subprojects).
subprojects {
if (path != ":common") {
// Apply the shadow plugin which lets us include contents
// of any libraries in our mod jars. Architectury uses it
// for bundling the common mod code in the platform jars.
apply(plugin = "com.github.johnrengelman.shadow")
fun Project.sourceSets() = extensions.getByName<SourceSetContainer>("sourceSets")

// Set a different run directory for the server run config,
// so it won't override client logs/config (or vice versa).
extensions.configure<LoomGradleExtensionAPI> {
runConfigs.getByName("server") {
// Generate IDE run configs for each run config.
runs.configureEach {
isIdeConfigGenerated = true
}

// Set a different run directory for the server so the log and config files don't conflict.
runs.named("server") {
runDir = "run/server"
}

// "main" matches the default NeoForge mod's name
with(mods.maybeCreate("main")) {
fun Project.sourceSets() = extensions.getByName<SourceSetContainer>("sourceSets")
sourceSet(sourceSets().getByName("main"))
sourceSet(project(":common").sourceSets().getByName("main"))
}
}

// Define the "bundle" configuration which will be included in the shadow jar.
val bundle by configurations.creating {
// This configuration is only meant to be resolved to its files but not published in
// any way, so we set canBeConsumed = false and canBeResolved = true.
// See https://docs.gradle.org/current/userguide/declaring_dependencies.html#sec:resolvable-consumable-configs.
isCanBeConsumed = false
isCanBeResolved = true
}

tasks {
"jar"(Jar::class) {
archiveClassifier.set("dev-slim")
}

"shadowJar"(ShadowJar::class) {
archiveClassifier.set("dev-shadow")
// Include our bundle configuration in the shadow jar.
configurations = listOf(bundle)
from(project(":common").sourceSets().named("main").map { it.output })
}

"remapJar"(RemapJarTask::class) {
dependsOn("shadowJar")
// Replace the remap jar task's input with the shadow jar containing the common classes.
inputFile.set(named<ShadowJar>("shadowJar").flatMap { it.archiveFile })
// The project name will be "fabric" or "neoforge", so this will become the classifier/suffix
// for the jar. For example: Adorn-3.4.0-fabric.jar
archiveClassifier.set(project.name)
Expand Down
9 changes: 0 additions & 9 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,6 @@ plugins {
id("adorn-data-generator")
}

architectury {
// Set up Architectury for the common project.
// This sets up the transformations (@ExpectPlatform etc.) we need for production environments.
common(
"fabric",
"neoforge",
)
}

loom {
accessWidenerPath.set(file("src/main/resources/adorn.accesswidener"))
}
Expand Down
2 changes: 2 additions & 0 deletions common/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Skip remapping jars for common code. We don't use them, and it slows down the build.
fabric.loom.dontRemap = true
19 changes: 2 additions & 17 deletions fabric/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
plugins {
id("adorn-data-generator")
id("adorn-data-generator.emi")
id("adorn-minify-json")
id("adorn-service-inline")
}

architectury {
// Create the IDE launch configurations for this subproject.
platformSetupLoomIde()
// Set up Architectury for Fabric.
fabric()
}

// The files below are for using the access widener for the common project.
// We need to copy the file from common resources to fabric resource
// for Fabric Loader to find it and not crash.
Expand Down Expand Up @@ -59,19 +53,14 @@ dependencies {
implementation(project(":common", configuration = "namedElements")) {
isTransitive = false
}
// Bundle the transformed version of the common project in the mod.
// The transformed version includes things like fixed refmaps.
bundle(project(path = ":common", configuration = "transformProductionFabric")) {
isTransitive = false
}

// Standard Fabric mod setup.
modImplementation(libs.fabric.loader)
modImplementation(libs.fabric.api)

// Bundle Jankson in the mod and use it as a regular "implementation" library.
implementation(libs.jankson)
bundle(libs.jankson)
include(libs.jankson)

// Mod compat
modCompileOnly(libs.towelette)
Expand All @@ -84,10 +73,6 @@ dependencies {
}

tasks {
shadowJar {
relocate("blue.endless.jankson", "juuxel.adorn.relocated.jankson")
}

processResources {
// Mark that this task depends on the project version,
// and should reset when the project version changes.
Expand Down
19 changes: 2 additions & 17 deletions forge/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
plugins {
id("adorn-data-generator")
id("adorn-data-generator.emi")
id("adorn-minify-json")
id("adorn-service-inline")
}

architectury {
// Create the IDE launch configurations for this subproject.
platformSetupLoomIde()
// Set up Architectury for NeoForge.
neoForge()
}

loom {
// Make the Forge project use the common access widener.
accessWidenerPath.set(project(":common").file("src/main/resources/adorn.accesswidener"))
Expand All @@ -35,14 +29,9 @@ dependencies {
implementation(project(":common", configuration = "namedElements")) {
isTransitive = false
}
// Bundle the transformed version of the common project in the mod.
// The transformed version includes things like fixed refmaps.
bundle(project(path = ":common", configuration = "transformProductionNeoForge")) {
isTransitive = false
}

// Bundle Jankson in the mod.
bundle(libs.jankson)
include(libs.jankson)
// Use Jankson as a library. Note that on Forge, regular non-mod libraries have to be declared
// using forgeRuntimeLibrary as Forge reads the runtime classpath from a separately generated file.
// In ForgeGradle projects, you might see a custom "library" configuration used for this.
Expand All @@ -54,10 +43,6 @@ dependencies {
}

tasks {
shadowJar {
relocate("blue.endless.jankson", "juuxel.adorn.relocated.jankson")
}

remapJar {
// Convert the access widener to a NeoForge access transformer.
atAccessWideners.add("adorn.accesswidener")
Expand Down

0 comments on commit 77cde5b

Please sign in to comment.