FabricMC / fabric-loom

Gradle build system plugin used to automate the setup of a minecraft mod development environment.
MIT License
221 stars 193 forks source link

Disabling compression in remapJar task causes a ZipException #1138

Open chylex opened 2 days ago

chylex commented 2 days ago

The following task configuration:

tasks.remapJar {
    entryCompression = ZipEntryCompression.STORED
}

fails with the following exception:

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':Fabric:remapJar'.
Caused by: org.gradle.workers.internal.DefaultWorkerExecutor$WorkExecutionException: A failure occurred while executing net.fabricmc.loom.task.RemapJarTask$RemapAction
Caused by: java.lang.RuntimeException: Failed to remap, java.util.zip.ZipException: STORED entry missing size, compressed size, or crc-32
    at net.fabricmc.loom.util.ExceptionUtil.createDescriptiveWrapper(ExceptionUtil.java:60)
    at net.fabricmc.loom.task.RemapJarTask$RemapAction.execute(RemapJarTask.java:276)
    ...
Caused by: java.util.zip.ZipException: STORED entry missing size, compressed size, or crc-32
    at net.fabricmc.loom.util.ZipReprocessorUtil.copyZipEntry(ZipReprocessorUtil.java:168)
    at net.fabricmc.loom.util.ZipReprocessorUtil.reprocessZip(ZipReprocessorUtil.java:125)
    at net.fabricmc.loom.task.AbstractRemapJarTask$AbstractRemapAction.rewriteJar(AbstractRemapJarTask.java:228)
    at net.fabricmc.loom.task.RemapJarTask$RemapAction.execute(RemapJarTask.java:258)
    ...

It would be useful to have the option to produce uncompressed jars, as it seems to lead to smaller multiloader jars if the nested jars are uncompressed.

A simple workaround is to create a second jar task that re-creates the output of remapJar:

tasks.register<Jar>("uncompressedRemapJar") {
    group = "fabric"

    from(tasks.remapJar.map { it.outputs.files.map(::zipTree) })

    archiveClassifier.set("uncompressed")
    entryCompression = ZipEntryCompression.STORED
}