Exclude unused shared objects/jni, reducing the jar final size by ~4.5x

Thanks earth for helping with hell
This commit is contained in:
mcrcortex
2025-01-04 00:22:22 +10:00
parent 1a3ad7d701
commit 2f7f7f4f6b
2 changed files with 37 additions and 1 deletions

5
.gitignore vendored
View File

@@ -1,3 +1,6 @@
# Project exclude paths
/.gradle/
/build/
/.idea/
/build/
/run/
/out/

View File

@@ -126,6 +126,39 @@ jar {
}
}
tasks.register('excludeUnused', Zip) {
//outputs.upToDateWhen { false }
archiveExtension.set("jar")
entryCompression(ZipEntryCompression.STORED)
destinationDirectory.set temporaryDir
archiveFileName.set processIncludeJars.outputDirectory.asFileTree.filter {
it.name.startsWith('rocksdb')
}.first().name
processIncludeJars.outputDirectory.asFileTree.each {
if (it.name.startsWith('rocksdb')) {
from zipTree(it)
}
}
exclude {
def file = it.name
if (file.endsWith(".jnilib")) {
return true
}
if (!file.endsWith(".so")) {
return false
}
return ["osx", "linux32", "s390x", "riscv64", "ppc64le", "aarch64"].any(file::contains)
}
dependsOn processIncludeJars
}
remapJar {
nestedJars = nestedJars.filter {
!it.name.startsWith('rocksdb')
}
nestedJars.from excludeUnused
}
project.ext.lwjglVersion = "3.3.3"
project.ext.lwjglNatives = "natives-windows"