diff --git a/build.gradle b/build.gradle index 2b4a4436..d6f7b689 100644 --- a/build.gradle +++ b/build.gradle @@ -10,7 +10,8 @@ plugins { id 'maven-publish' id 'org.jetbrains.gradle.plugin.idea-ext' version '1.4.1' id 'com.gtnewhorizons.retrofuturagradle' version '2.0.2' - id 'com.diffplug.spotless' version '8.5.1' + id 'com.gradleup.shadow' version '9.4.2' + id 'com.diffplug.spotless' version '8.6.0' } apply from: 'gradle/scripts/helpers.gradle' @@ -22,7 +23,6 @@ assertProperty 'mod_id' assertProperty 'mod_name' assertSubProperties 'use_tags', 'tag_class_name' -assertSubProperties 'use_lombok_ap', 'lombok_version' assertSubProperties 'use_access_transformer', 'access_transformer_locations' assertSubProperties 'use_mixins', 'mixin_booter_version', 'mixin_refmap' assertSubProperties 'is_coremod', 'coremod_includes_mod', 'coremod_plugin_class_name' @@ -47,7 +47,7 @@ base { archivesName = propertyString('mod_id') } -tasks.decompressDecompiledSources.enabled !propertyBool('change_minecraft_sources') +tasks.decompressDecompiledSources.enabled !propertyBool('change_minecraft_sources') || !layout.buildDirectory.dir('rfg/minecraft-src').get().asFile.exists() java { toolchain { @@ -64,8 +64,8 @@ java { } configurations { - embed - implementation.extendsFrom(embed) + shaded + implementation.extendsFrom shaded } minecraft { @@ -93,9 +93,13 @@ minecraft { if (propertyBool('use_tags')) { if (file('tags.properties').exists()) { - Properties props = new Properties().tap { it.load(file('tags.properties').newInputStream()); it } + Properties props = new Properties().tap { it.load(file('tags.properties').newInputStream()); it } if (!props.isEmpty()) { - injectedTags.set(props.collectEntries { k, v -> [(k): interpolate(v)] }) + injectedTags.set(props.collectEntries { k, v -> + def interpolated = interpolate(v) + if (interpolated == null || interpolated.isEmpty()) throw new GradleException("Empty tag value found for key: $k") + [(k): interpolated] + }) } } } @@ -124,13 +128,6 @@ dependencies { transitive = false // We only care about the 1 annotation class } } - if (propertyBool('use_lombok_ap')) { - compileOnly "org.projectlombok:lombok:${propertyString('lombok_version')}" - annotationProcessor "org.projectlombok:lombok:${propertyString('lombok_version')}" - - testCompileOnly "org.projectlombok:lombok:${propertyString('lombok_version')}" - testAnnotationProcessor "org.projectlombok:lombok:${propertyString('lombok_version')}" - } if (propertyBool('use_asset_mover')) { implementation "com.cleanroommc:assetmover:${propertyString('asset_mover_version')}" } @@ -238,8 +235,27 @@ jar { } attributes(attribute_map) } - // Add all embedded dependencies into the jar - from(provider{ configurations.embed.collect {it.isDirectory() ? it : zipTree(it)} }) +} + +// Shade deps to the dev jar, so the normal dev jar will contain deps +shadowJar { + archiveClassifier = 'dev' + configurations = [ project.configurations.shaded ] +} + +if (propertyBool('enable_shadow')) { + // Unshaded dev jar get 'plain' as name + tasks.named("jar").configure { + archiveClassifier = "plain" + } + // Here we reobf the shaded dev jar, so the final obf jar will contain deps + tasks.named('reobfJar').configure { + inputJar.set(tasks.named('shadowJar').flatMap { it.archiveFile }) + } +} else { + tasks.named('shadowJar').configure { + enabled = false + } } idea { diff --git a/gradle.properties b/gradle.properties index 8f671940..6b85077e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,9 +4,6 @@ org.gradle.jvmargs = -Xmx3G # Source Options # Use Modern Java(9+) Syntax (Courtesy of Jabel) use_modern_java_syntax = false -# Use Lombok annotation processor -use_lombok_ap = false -lombok_version = 1.18.46 # Compilation Options generate_sources_jar = true @@ -16,6 +13,11 @@ generate_javadocs_jar = false enable_junit_testing = true show_testing_output = false +# Shadow +# This will rename the 'dev' jar to 'plain' and replace 'dev' with a shaded jar +# Deps will be shaded into the final obf jar with no suffix too +enable_shadow = false + # Mod Information # HIGHLY RECOMMEND complying with SemVer for mod_version: https://semver.org/ mod_version = 1.0.0 @@ -24,8 +26,12 @@ mod_id = modid mod_name = Mod Name # Mod Metadata (Optional) +# Use tags.properties to bring these values into your Tags class (see below: use_tags) mod_description = mod_url = +# A url where the mod's update json can be fetched +# Wiki: https://docs.minecraftforge.net/en/1.12.x/gettingstarted/autoupdate/#forge-update-checker +# Also see: https://curseupdate.com + https://docs.modrinth.com/api/operations/forgeupdates mod_update_json = # Delimit authors with commas. Eg: Author1,Author2 mod_authors = diff --git a/gradle/scripts/dependencies.gradle b/gradle/scripts/dependencies.gradle index baba46a1..97a8858a 100644 --- a/gradle/scripts/dependencies.gradle +++ b/gradle/scripts/dependencies.gradle @@ -37,6 +37,11 @@ dependencies { // By wrapping a dependency descriptor in rfg.deobf() method call, the dependency is queued for deobfuscation // When deobfuscating, RFG respects the mapping_channel + mapping_version stated in gradle.properties + // Example - Shading dependencies: + // Using the shadow plugin, by using the "shaded" configuration, the dependency will be shaded into your output jar + // shaded 'mezz:jei:4.31.2' << will shade HadEnoughItems 4.31.2 directly into your jar + // For more configuration options: see the bottom of this file and: https://gradleup.com/shadow/configuration/ + // Example - CurseMaven dependencies: // 'curse.maven:had-enough-items-557549:4543375' << had-enough-items = project slug, 557549 = project id, 4543375 = file id // Full documentation: https://cursemaven.com/ @@ -53,7 +58,7 @@ dependencies { // runtimeOnly = runtime dependency // compileOnly = compile time dependency // annotationProcessor = annotation processing dependencies - // embed = bundle dependencies into final output artifact (no relocation) + // shaded = includes dependency in output // Transitive dependencies: // (Dependencies that your dependency depends on) @@ -63,3 +68,16 @@ dependencies { // transitive = false // } } + +tasks.named("shadowJar").configure { + // Exclude specific parts of deps to keep your jar clean + // dependencies { + // exclude 'META-INF/maven/**' + // } + + // Relocate specific parts of deps, so multiple shaded classes in mods will not conflict + // relocate "mezz.jei", "shaded.mezz.jei" + + // Remove unused classes automatically. May cause issues if they are accessed by reflection + // minimize() +}