From 2f7f7f4f6ba6328a7416a4619c7ce5bd10719b02 Mon Sep 17 00:00:00 2001 From: mcrcortex <18544518+MCRcortex@users.noreply.github.com> Date: Sat, 4 Jan 2025 00:22:22 +1000 Subject: [PATCH] Exclude unused shared objects/jni, reducing the jar final size by ~4.5x Thanks earth for helping with hell --- .gitignore | 5 ++++- build.gradle | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index b740e729..c44ef9af 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ # Project exclude paths /.gradle/ -/build/ \ No newline at end of file +/.idea/ +/build/ +/run/ +/out/ diff --git a/build.gradle b/build.gradle index 97aa5a72..510c9874 100644 --- a/build.gradle +++ b/build.gradle @@ -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"