From 6b723311d2ce7f819a822127e0be7a9dddd55b25 Mon Sep 17 00:00:00 2001
From: BenCodez <17074231+BenCodez@users.noreply.github.com>
Date: Wed, 18 Nov 2026 03:04:03 +0000
Subject: [PATCH 1/2] Recompress downloadable JAR without changing entry
payloads
---
VotingPlugin/pom.xml | 34 +++++++++++++++++++
.../tests/packaging/PackagedArtifactTest.java | 33 ++++++++++++++++++
docs/jar-recompression.md | 27 +++++++++++++++
3 files changed, 94 insertions(+)
create mode 100644 docs/jar-recompression.md
diff --git a/VotingPlugin/pom.xml b/VotingPlugin/pom.xml
index e588f8a48..8460f382d 100644
--- a/VotingPlugin/pom.xml
+++ b/VotingPlugin/pom.xml
@@ -12,6 +12,8 @@
UTF-8
NOTSET
${project.name}
+
+ true
21
21
21
@@ -268,6 +270,37 @@
+
+ org.apache.maven.plugins
+ maven-antrun-plugin
+ 3.2.0
+
+
+ recompress-downloadable-jar
+ package
+ run
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
org.apache.maven.plugins
maven-surefire-plugin
@@ -290,6 +323,7 @@
${project.build.directory}/packaged-artifact-reports
${project.build.directory}/${packaged.jar.name}.jar
+ ${project.build.directory}/jar-recompression-input.jar
diff --git a/VotingPlugin/src/test/java/com/bencodez/votingplugin/tests/packaging/PackagedArtifactTest.java b/VotingPlugin/src/test/java/com/bencodez/votingplugin/tests/packaging/PackagedArtifactTest.java
index 4c8303601..05c42a12a 100644
--- a/VotingPlugin/src/test/java/com/bencodez/votingplugin/tests/packaging/PackagedArtifactTest.java
+++ b/VotingPlugin/src/test/java/com/bencodez/votingplugin/tests/packaging/PackagedArtifactTest.java
@@ -17,6 +17,8 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.jar.JarFile;
+import java.util.jar.JarInputStream;
+import java.util.stream.Collectors;
import javax.tools.ToolProvider;
import org.junit.jupiter.api.Test;
@@ -26,6 +28,33 @@
public class PackagedArtifactTest {
private static final long ARTIFACT_SIZE_TARGET_BYTES = 10L * 1024L * 1024L;
+ @Test
+ void recompressionPreservesEveryEntryAndStreamingManifest() throws Exception {
+ Path input = Path.of(System.getProperty("votingplugin.precompressionJar"));
+ Path output = packagedJar();
+ try (JarFile before = new JarFile(input.toFile()); JarFile after = new JarFile(output.toFile())) {
+ var beforeNames = before.stream().map(entry -> entry.getName()).collect(Collectors.toList());
+ var afterNames = after.stream().map(entry -> entry.getName()).collect(Collectors.toList());
+ assertEquals(beforeNames.size(), new java.util.HashSet<>(beforeNames).size(),
+ "The shaded input must not contain duplicate entry names");
+ assertEquals(afterNames.size(), new java.util.HashSet<>(afterNames).size(),
+ "Recompression must not create duplicate entry names");
+ assertEquals(new java.util.HashSet<>(beforeNames), new java.util.HashSet<>(afterNames),
+ "Recompression must retain every class, directory and resource");
+ for (String name : beforeNames) {
+ try (var original = before.getInputStream(before.getEntry(name));
+ var recompressed = after.getInputStream(after.getEntry(name))) {
+ assertArrayEquals(original.readAllBytes(), recompressed.readAllBytes(), name);
+ }
+ }
+ assertEquals(before.getComment(), after.getComment(), "The archive comment must be retained");
+ }
+ try (JarInputStream streaming = new JarInputStream(Files.newInputStream(output))) {
+ assertNotNull(streaming.getManifest(), "Streaming readers must see the manifest first");
+ }
+ System.out.printf("Lossless JAR recompression: %,d -> %,d bytes%n", Files.size(input), Files.size(output));
+ }
+
@Test
void containsOneRelocatedRuntimeWithoutUnusedHttpCrypto() throws Exception {
Path artifactPath = packagedJar();
@@ -58,6 +87,10 @@ void containsOneRelocatedRuntimeWithoutUnusedHttpCrypto() throws Exception {
"com/bencodez/votingplugin/simpleapi/scheduler/BukkitScheduler.class"));
assertNotNull(artifact.getEntry(
"com/bencodez/votingplugin/simpleapi/hikari/HikariDataSource.class"));
+ assertNotNull(artifact.getEntry("com/bencodez/simpleapi/configurate/ConfigurationNode.class"));
+ assertFalse(artifact.stream().anyMatch(entry -> entry.getName()
+ .startsWith("com/bencodez/votingplugin/simpleapi/configurate/")),
+ "A repeated package must not shade the previous output into a second Configurate namespace");
assertNull(artifact.getEntry("org/mozilla/javascript/Context.class"));
assertNull(artifact.getEntry("com/zaxxer/hikari/HikariDataSource.class"));
diff --git a/docs/jar-recompression.md b/docs/jar-recompression.md
new file mode 100644
index 000000000..591c9022c
--- /dev/null
+++ b/docs/jar-recompression.md
@@ -0,0 +1,27 @@
+# Lossless downloadable JAR recompression
+
+After shading, the package phase repacks the downloadable JAR with standard
+DEFLATE level 9. Entry names and uncompressed content remain identical,
+including services, licenses, manifests and native libraries. ZIP attributes
+and entry timestamps may be normalized. A package-phase comparison checks the complete
+input/output inventories and bytes, and verifies that streaming JAR readers
+still see the manifest first. The artifact name and runtime dependencies stay
+the same; the added Ant task is build-only.
+
+The repacker follows Shade and precedes the packaged-artifact tests. It keeps
+ZIP64 support automatic, uses UTF-8 entry names, rejects duplicate names, and
+includes the existing manifest before the remaining resources. It does not
+rewrite the manifest. Deployment profiles use the existing `packaged.jar.name`
+property, so the normal artifact path is preserved.
+
+All profiles force Maven to recreate the project JAR before Shade, even when
+inputs are unchanged. This prevents a previous shaded/recompressed artifact
+from being reused as the next Shade input. The package test also rejects a
+second Configurate namespace created by shading an already shaded JAR.
+
+The shaded comparison input remains in `target/` without being attached as a
+publication artifact. The staged archive is moved to the normal downloadable
+path after repacking. The package test compares every input/output
+entry and its bytes, then opens the final JAR through `JarInputStream` to check
+streaming manifest discovery. Compression savings are reported without adding
+a build-failing size threshold. The existing advisory size warning still applies.
From 523931975e4a5b787a4360caff34e73679bd1bb7 Mon Sep 17 00:00:00 2001
From: BenCodez <17074231+BenCodez@users.noreply.github.com>
Date: Wed, 18 Nov 2026 06:13:02 +0000
Subject: [PATCH 2/2] Skip package-only artifact comparison before reading
optional paths
---
.../votingplugin/tests/packaging/PackagedArtifactTest.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/VotingPlugin/src/test/java/com/bencodez/votingplugin/tests/packaging/PackagedArtifactTest.java b/VotingPlugin/src/test/java/com/bencodez/votingplugin/tests/packaging/PackagedArtifactTest.java
index 05c42a12a..55195bdff 100644
--- a/VotingPlugin/src/test/java/com/bencodez/votingplugin/tests/packaging/PackagedArtifactTest.java
+++ b/VotingPlugin/src/test/java/com/bencodez/votingplugin/tests/packaging/PackagedArtifactTest.java
@@ -30,8 +30,8 @@ public class PackagedArtifactTest {
@Test
void recompressionPreservesEveryEntryAndStreamingManifest() throws Exception {
- Path input = Path.of(System.getProperty("votingplugin.precompressionJar"));
Path output = packagedJar();
+ Path input = Path.of(System.getProperty("votingplugin.precompressionJar"));
try (JarFile before = new JarFile(input.toFile()); JarFile after = new JarFile(output.toFile())) {
var beforeNames = before.stream().map(entry -> entry.getName()).collect(Collectors.toList());
var afterNames = after.stream().map(entry -> entry.getName()).collect(Collectors.toList());