build: merge shadow jar access wideners
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
||||
import com.google.common.hash.Hashing
|
||||
import com.google.devtools.ksp.gradle.KspAATask
|
||||
import com.google.gson.Gson
|
||||
@@ -29,7 +30,6 @@ plugins {
|
||||
// alias(libs.plugins.loom)
|
||||
// TODO: use arch loom once they update to 1.8
|
||||
id("fabric-loom") version "1.10.1"
|
||||
alias(libs.plugins.shadow)
|
||||
id("moe.nea.licenseextractificator")
|
||||
alias(libs.plugins.mcAutoTranslations)
|
||||
}
|
||||
@@ -130,6 +130,9 @@ val collectTranslations by tasks.registering(CollectTranslations::class) {
|
||||
this.classes.from(sourceSets.main.get().kotlin.classesDirectory)
|
||||
}
|
||||
|
||||
val shadowJar = tasks.register("shadowJar", ShadowJar::class)
|
||||
val mergedSourceSetsJar = tasks.register("mergedSourceSetsJar", ShadowJar::class)
|
||||
|
||||
val compatSourceSets: MutableSet<SourceSet> = mutableSetOf()
|
||||
fun createIsolatedSourceSet(name: String, path: String = "compat/$name", isEnabled: Boolean = true): SourceSet {
|
||||
val ss = sourceSets.create(name) {
|
||||
@@ -178,7 +181,7 @@ fun createIsolatedSourceSet(name: String, path: String = "compat/$name", isEnabl
|
||||
(ss.implementationConfigurationName)(project.files(tasks.compileKotlin.map { it.destinationDirectory }))
|
||||
(ss.implementationConfigurationName)(project.files(tasks.compileJava.map { it.destinationDirectory }))
|
||||
}
|
||||
tasks.shadowJar {
|
||||
mergedSourceSetsJar.configure {
|
||||
from(ss.output)
|
||||
}
|
||||
// TODO: figure out why inheritances are not being respected by tiny kotlin names
|
||||
@@ -268,8 +271,7 @@ dependencies {
|
||||
nonModImplentation("com.google.auto.service:auto-service-annotations:1.1.1")
|
||||
ksp("dev.zacsweers.autoservice:auto-service-ksp:1.2.0")
|
||||
include(libs.manninghamMills)
|
||||
include(libs.moulconfig)
|
||||
|
||||
shadowMe(libs.moulconfig)
|
||||
|
||||
annotationProcessor(libs.mixinextras)
|
||||
nonModImplentation(libs.mixinextras)
|
||||
@@ -437,22 +439,33 @@ tasks.jar {
|
||||
destinationDirectory.set(layout.buildDirectory.dir("badjars"))
|
||||
archiveClassifier.set("slim")
|
||||
}
|
||||
|
||||
tasks.shadowJar {
|
||||
configurations = listOf(shadowMe)
|
||||
archiveClassifier.set("dev")
|
||||
relocate("io.github.moulberry.repo", "moe.nea.firmament.deps.repo")
|
||||
mergedSourceSetsJar.configure {
|
||||
from(zipTree(tasks.jar.flatMap { it.archiveFile }))
|
||||
destinationDirectory.set(layout.buildDirectory.dir("badjars"))
|
||||
archiveClassifier.set("merged-source-sets")
|
||||
mergeServiceFiles()
|
||||
}
|
||||
shadowJar.configure {
|
||||
from(zipTree(tasks.remapJar.flatMap { it.archiveFile }))
|
||||
configurations = listOf(shadowMe)
|
||||
archiveClassifier.set("")
|
||||
relocate("io.github.moulberry.repo", "moe.nea.firmament.deps.repo")
|
||||
relocate("io.github.notenoughupdates.moulconfig", "moe.nea.firmament.deps.moulconfig")
|
||||
mergeServiceFiles()
|
||||
transform<FabricModTransform>()
|
||||
}
|
||||
|
||||
tasks.remapJar {
|
||||
// injectAccessWidener.set(true)
|
||||
inputFile.set(tasks.shadowJar.flatMap { it.archiveFile })
|
||||
dependsOn(tasks.shadowJar)
|
||||
archiveClassifier.set("")
|
||||
inputFile.set(mergedSourceSetsJar.flatMap { it.archiveFile })
|
||||
dependsOn(mergedSourceSetsJar)
|
||||
destinationDirectory.set(layout.buildDirectory.dir("badjars"))
|
||||
archiveClassifier.set("remapped")
|
||||
}
|
||||
|
||||
tasks.assemble { dependsOn(shadowJar) }
|
||||
|
||||
|
||||
tasks.processResources {
|
||||
val replacements = listOf(
|
||||
"version" to project.version.toString(),
|
||||
|
||||
@@ -3,25 +3,27 @@
|
||||
// SPDX-License-Identifier: CC0-1.0
|
||||
|
||||
plugins {
|
||||
kotlin("jvm") version "2.1.0"
|
||||
`kotlin-dsl`
|
||||
kotlin("jvm") version "2.1.0"
|
||||
`kotlin-dsl`
|
||||
}
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven {
|
||||
name = "jitpack"
|
||||
url = uri("https://jitpack.io")
|
||||
}
|
||||
mavenCentral()
|
||||
maven {
|
||||
name = "jitpack"
|
||||
url = uri("https://jitpack.io")
|
||||
}
|
||||
}
|
||||
dependencies {
|
||||
implementation("com.github.romangraef:neaslicenseextractificator:1.1.0")
|
||||
implementation("com.google.code.gson:gson:2.10.1")
|
||||
implementation("com.github.romangraef:neaslicenseextractificator:1.1.0")
|
||||
api("com.gradleup.shadow:shadow-gradle-plugin:9.0.0-rc1")
|
||||
implementation("net.fabricmc:access-widener:2.1.0")
|
||||
implementation("com.google.code.gson:gson:2.10.1")
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
main {
|
||||
kotlin {
|
||||
srcDir(file("src"))
|
||||
}
|
||||
}
|
||||
main {
|
||||
kotlin {
|
||||
srcDir(file("src"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
80
buildSrc/src/FabricModTransform.kt
Normal file
80
buildSrc/src/FabricModTransform.kt
Normal file
@@ -0,0 +1,80 @@
|
||||
import com.github.jengelman.gradle.plugins.shadow.transformers.ResourceTransformer
|
||||
import com.github.jengelman.gradle.plugins.shadow.transformers.TransformerContext
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.JsonObject
|
||||
import com.google.gson.JsonPrimitive
|
||||
import java.io.Serializable
|
||||
import net.fabricmc.accesswidener.AccessWidenerReader
|
||||
import net.fabricmc.accesswidener.AccessWidenerWriter
|
||||
import org.apache.tools.zip.ZipEntry
|
||||
import org.apache.tools.zip.ZipOutputStream
|
||||
import org.gradle.api.file.FileTreeElement
|
||||
import org.gradle.api.provider.Property
|
||||
import org.gradle.api.tasks.Input
|
||||
import org.gradle.api.tasks.Internal
|
||||
|
||||
open class FabricModTransform : ResourceTransformer {
|
||||
|
||||
enum class AccessWidenerInclusion : Serializable {
|
||||
ALL,
|
||||
NONE,
|
||||
}
|
||||
|
||||
@get:Input
|
||||
var mergeAccessWideners: AccessWidenerInclusion = AccessWidenerInclusion.ALL
|
||||
|
||||
@get:Internal
|
||||
internal var mergedFmj: JsonObject? = null
|
||||
|
||||
@get:Internal
|
||||
internal val foundAccessWideners = AccessWidenerWriter()
|
||||
|
||||
@get:Internal
|
||||
internal var foundAnyAccessWidener = false
|
||||
|
||||
override fun canTransformResource(element: FileTreeElement): Boolean {
|
||||
if (mergeAccessWideners == AccessWidenerInclusion.ALL && element.name.endsWith(".accesswidener"))
|
||||
return true
|
||||
return element.path == "fabric.mod.json"
|
||||
}
|
||||
|
||||
override fun transform(context: TransformerContext) {
|
||||
if (context.path.endsWith(".accesswidener")) {
|
||||
foundAnyAccessWidener = true
|
||||
// TODO: allow filtering for only those mentioned in a fabric.mod.json, potentially
|
||||
context.inputStream.use { stream ->
|
||||
AccessWidenerReader(foundAccessWideners).read(stream.bufferedReader())
|
||||
}
|
||||
return
|
||||
}
|
||||
// TODO: mixins.json relocations
|
||||
val fmj = context.inputStream.use { stream ->
|
||||
Gson().fromJson(stream.bufferedReader(), JsonObject::class.java)
|
||||
}
|
||||
val mergedFmj = this.mergedFmj
|
||||
println("${fmj["id"]} is first? ${mergedFmj == null}")
|
||||
if (mergedFmj == null) {
|
||||
this.mergedFmj = fmj
|
||||
} else {
|
||||
// TODO: merge stuff
|
||||
}
|
||||
}
|
||||
|
||||
override fun hasTransformedResource(): Boolean {
|
||||
return mergedFmj != null
|
||||
}
|
||||
|
||||
override fun modifyOutputStream(os: ZipOutputStream, preserveFileTimestamps: Boolean) {
|
||||
val mergedFmj = mergedFmj!!
|
||||
if (foundAnyAccessWidener) {
|
||||
val awFile = mergedFmj["accessWidener"]
|
||||
require(awFile is JsonPrimitive && awFile.isString)
|
||||
os.putNextEntry(ZipEntry(awFile.asString))
|
||||
os.write(foundAccessWideners.write())
|
||||
os.closeEntry()
|
||||
}
|
||||
os.putNextEntry(ZipEntry("fabric.mod.json"))
|
||||
os.write(mergedFmj.toString().toByteArray())
|
||||
os.closeEntry()
|
||||
}
|
||||
}
|
||||
@@ -40,6 +40,8 @@ ncr = "Fabric-1.21.5-v2.12.0"
|
||||
# Update from https://modrinth.com/mod/female-gender/versions?l=fabric
|
||||
femalegender = "4.3.4+1.21.5"
|
||||
|
||||
shadow = "8.3.8"
|
||||
|
||||
# Update from https://modrinth.com/mod/explosive-enhancement/versions?l=fabric
|
||||
explosiveenhancement = "1.2.3-1.21.0"
|
||||
|
||||
@@ -135,7 +137,7 @@ femalegender = { module = "maven.modrinth:female-gender", version.ref = "femaleg
|
||||
jade = { module = "maven.modrinth:jade", version.ref = "jade" }
|
||||
yacl = { module = "dev.isxander:yet-another-config-lib", version.ref = "yacl" }
|
||||
basicMath = { module = "me.shedaniel.cloth:basic-math", version.ref = "basicMath" }
|
||||
|
||||
shadow = { module = "com.gradleup.shadow:shadow-gradle-plugin", version.ref = "shadow" }
|
||||
classTransform-mixinsTranslator = { module = "net.lenni0451.classtransform:mixinstranslator", version.ref = "classtransform" }
|
||||
classTransform-core = { module = "net.lenni0451.classtransform:core", version.ref = "classtransform" }
|
||||
|
||||
@@ -162,5 +164,4 @@ kotlin_plugin_serialization = { id = "org.jetbrains.kotlin.plugin.serialization"
|
||||
kotlin_plugin_powerassert = { id = "org.jetbrains.kotlin.plugin.power-assert", version.ref = "kotlin" }
|
||||
kotlin_plugin_ksp = { id = "com.google.devtools.ksp", version.ref = "kotlin_ksp" }
|
||||
loom = { id = "dev.architectury.loom", version.ref = "loom" }
|
||||
shadow = { id = "com.github.johnrengelman.shadow", version = "8.1.1" }
|
||||
mcAutoTranslations = { id = "moe.nea.mc-auto-translations", version.ref = "mcAutoTranslations" }
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
plugins {
|
||||
java
|
||||
alias(libs.plugins.shadow)
|
||||
id("com.gradleup.shadow")
|
||||
}
|
||||
dependencies {
|
||||
implementation(libs.asm)
|
||||
|
||||
Reference in New Issue
Block a user