Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 109 additions & 0 deletions VotingPlugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
<maven.compiler.release>21</maven.compiler.release>
<velocity.version>3.4.0</velocity.version>
<neoforge.version>21.1.211</neoforge.version>
<!-- Explicit opt-in profiles deactivate the default profile; keep its metadata fallback. -->
<build.profile.id>default</build.profile.id>
<platform.main.enabled>false</platform.main.enabled>
<platform.neoforge.enabled>false</platform.neoforge.enabled>
</properties>
<build>
<finalName>${packaged.jar.name}</finalName>
Expand Down Expand Up @@ -273,6 +277,12 @@
</execution>
</executions>
</plugin>
<!-- Profile artifacts are derived after Shade, before package-phase validation. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>3.2.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
Expand All @@ -295,6 +305,10 @@
<reportsDirectory>${project.build.directory}/packaged-artifact-reports</reportsDirectory>
<systemPropertyVariables>
<votingplugin.packagedJar>${project.build.directory}/${packaged.jar.name}.jar</votingplugin.packagedJar>
<votingplugin.mainJar>${project.build.directory}/${packaged.jar.name}-main.jar</votingplugin.mainJar>
<votingplugin.neoForgeJar>${project.build.directory}/${packaged.jar.name}-neoforge.jar</votingplugin.neoForgeJar>
<votingplugin.testMainArtifact>${platform.main.enabled}</votingplugin.testMainArtifact>
<votingplugin.testNeoForgeArtifact>${platform.neoforge.enabled}</votingplugin.testNeoForgeArtifact>
</systemPropertyVariables>
</configuration>
</execution>
Expand Down Expand Up @@ -581,6 +595,101 @@
</dependency>
</dependencies>
<profiles>
<profile>
<id>platform-main</id>
<properties>
<platform.main.enabled>true</platform.main.enabled>
<!-- Never feed a previously shaded JAR back through Shade. -->
<maven.jar.forceCreation>true</maven.jar.forceCreation>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<archive><manifestEntries>
<paperweight-mappings-namespace>mojang</paperweight-mappings-namespace>
</manifestEntries></archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>attach-platform-main</id>
<phase>package</phase>
<goals><goal>run</goal></goals>
<configuration>
<target>
<delete file="${project.build.directory}/${packaged.jar.name}-main.jar" />
<zip destfile="${project.build.directory}/${packaged.jar.name}-main.jar"
encoding="UTF-8" zip64Mode="as-needed" duplicate="fail">
<zipfileset src="${project.build.directory}/${packaged.jar.name}.jar"
includes="META-INF/MANIFEST.MF" />
<zipfileset src="${project.build.directory}/${packaged.jar.name}.jar"
excludes="META-INF/MANIFEST.MF,com/bencodez/votingplugin/neoforge/**,META-INF/neoforge.mods.toml" />
</zip>
<attachartifact file="${project.build.directory}/${packaged.jar.name}-main.jar"
classifier="main" type="jar" />
</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>platform-neoforge</id>
<properties>
<platform.neoforge.enabled>true</platform.neoforge.enabled>
<!-- Never feed a previously shaded JAR back through Shade. -->
<maven.jar.forceCreation>true</maven.jar.forceCreation>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<archive><manifestEntries>
<paperweight-mappings-namespace>mojang</paperweight-mappings-namespace>
</manifestEntries></archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>attach-platform-neoforge</id>
<phase>package</phase>
<goals><goal>run</goal></goals>
<configuration>
<target>
<delete file="${project.build.directory}/${packaged.jar.name}-neoforge.jar" />
<zip destfile="${project.build.directory}/${packaged.jar.name}-neoforge.jar"
encoding="UTF-8" zip64Mode="as-needed" duplicate="fail">
<zipfileset src="${project.build.directory}/${packaged.jar.name}.jar"
includes="META-INF/MANIFEST.MF" />
<zipfileset src="${project.build.directory}/${packaged.jar.name}.jar"
excludes="META-INF/MANIFEST.MF,plugin.yml,bungee.yml,velocity-plugin.json" />
</zip>
<attachartifact file="${project.build.directory}/${packaged.jar.name}-neoforge.jar"
classifier="neoforge" type="jar" />
</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>

<profile>
<id>default</id>
<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,58 @@ void packagedJdkTlsIdentityWorksWithoutExternalCrypto(@TempDir Path directory) t
}
}

@Test
void mainProfilePreservesEveryUnrelatedEntry() throws Exception {
org.junit.jupiter.api.Assumptions.assumeTrue(
Boolean.getBoolean("votingplugin.testMainArtifact"), "Main profile is opt-in");
assertPlatformSubset("votingplugin.mainJar", name ->
name.startsWith("com/bencodez/votingplugin/neoforge/")
|| name.equals("META-INF/neoforge.mods.toml"));
}

@Test
void neoForgeProfileOnlyChangesPlatformDiscovery() throws Exception {
org.junit.jupiter.api.Assumptions.assumeTrue(
Boolean.getBoolean("votingplugin.testNeoForgeArtifact"), "NeoForge profile is opt-in");
assertPlatformSubset("votingplugin.neoForgeJar", name ->
name.equals("plugin.yml") || name.equals("bungee.yml")
|| name.equals("velocity-plugin.json"));
}

private static void assertPlatformSubset(String property,
java.util.function.Predicate<String> excluded) throws Exception {
Path original = packagedJar();
Path selected = Path.of(System.getProperty(property));
assertTrue(Files.isRegularFile(selected), "Requested platform artifact must be produced");
try (JarFile before = new JarFile(original.toFile()); JarFile after = new JarFile(selected.toFile())) {
var expected = before.stream().filter(entry -> !excluded.test(entry.getName()))
.map(java.util.zip.ZipEntry::getName).collect(java.util.stream.Collectors.toSet());
var entries = after.stream().map(java.util.zip.ZipEntry::getName).toList();
assertEquals(entries.size(), new java.util.HashSet<>(entries).size());
assertEquals(expected, new java.util.HashSet<>(entries));
String version = new String(after.getInputStream(after.getEntry("votingpluginversion.yml"))
.readAllBytes(), StandardCharsets.UTF_8);
assertFalse(version.contains("${build.profile.id}"), "Profile metadata must be resolved");
for (String name : expected) {
try (var input = before.getInputStream(before.getEntry(name));
var output = after.getInputStream(after.getEntry(name))) {
byte[] retained = output.readAllBytes();
assertArrayEquals(input.readAllBytes(), retained, name);
if (property.equals("votingplugin.mainJar") && name.endsWith(".class")) {
assertFalse(new String(retained, StandardCharsets.ISO_8859_1)
.contains("com/bencodez/votingplugin/neoforge/"),
"Retained classes must not link to the removed adapter: " + name);
}
}
}
assertEquals(before.getComment(), after.getComment());
assertNotNull(after.getManifest());
}
try (var input = new java.util.jar.JarInputStream(Files.newInputStream(selected))) {
assertNotNull(input.getManifest(), "Streaming readers must see the original manifest");
}
}

private static Path packagedJar() {
String configured = System.getProperty("votingplugin.packagedJar");
assumeTrue(configured != null, "Packaged artifact is available only in the package lifecycle");
Expand Down
60 changes: 60 additions & 0 deletions docs/platform-packaging.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Opt-in platform packaging

The normal `mvn -B -f VotingPlugin/pom.xml clean package` contract is unchanged:
`VotingPlugin/target/VotingPlugin.jar` remains the universal main artifact, with
its existing coordinates and platform discovery metadata. No Jenkins, Nexus or
other download consumer is switched by this change.

Two optional profiles attach additional artifacts after shading:

| Maven profile | Additional local file | Maven classifier | Discovery |
| --- | --- | --- | --- |
| `platform-main` | `VotingPlugin-main.jar` | `main` | Bukkit/Spigot/Paper/Folia, BungeeCord and Velocity |
| `platform-neoforge` | `VotingPlugin-neoforge.jar` | `neoforge` | NeoForge only |

Run either profile, or both together:

```sh
mvn -B -f VotingPlugin/pom.xml -Pplatform-main,platform-neoforge clean package
```

Files use `${packaged.jar.name}` when an existing build overrides that property.
The unclassified artifact is still built and remains the source of both attached
artifacts. Existing deploy profiles may be combined explicitly; no install or
deploy is necessary to build the files. These profiles force fresh JAR creation
to prevent reshading a previous shaded output. They preserve the mapping manifest
entry even though selecting a profile disables Maven's active-by-default profile.
Do not use the developer-specific `dev` profile in automation.

The main classifier removes only the NeoForge adapter package and its discovery
metadata. It preserves proxy/backend support, shared core, libraries, license
notices, services, configuration defaults and every SQLite entry in its input.
The NeoForge classifier removes only the three other platform discovery files;
it deliberately retains implementation and dependency classes until a separate
compatibility assessment proves a narrower closure safe. It is a separate
installable file, not a claim of a lightweight neutral library or native runtime
acceptance. No dependency minimization, new runtime download or engine substitution
is used. ZIP64 remains automatic, the manifest is first, and retained entry bytes
must match the universal artifact in package-phase checks.

The current default branch's SQLite native policy is inherited, not broadened or
narrowed here. It does not embed every supported native architecture. Restoring
full supported offline/native behavior is a separate dependency acceptance gate;
these profile checks must not be represented as Windows/native acceptance. The
frozen dependency candidate is not modified. Once that work is integrated, every
additional SQLite/native/resource entry automatically flows to both classifiers
and is covered by the retained-byte comparison. Custom native override behavior
is not changed by profile extraction.

Fabric has an existing standalone Gradle/Loom bootstrap in a separate open change.
It is not on this baseline and does not yet implement the full vote-processing
feature set. This change does not duplicate it, rename its remapped output or
present a Maven ZIP as a remapped Fabric mod. A Maven orchestration profile needs
the actual module, wrapper/build-tool contract, mapping/remap output and owning
maintainer agreement first. No Fabric artifact is advertised by these profiles.

A future switch of the default download to the main classifier needs an explicit
artifact/download migration decision and consumer validation. Changing default
coordinates or replacing a universal artifact is outside this opt-in change.
These classifiers alone do not promise a multi-megabyte reduction; measured
savings must be reported for final files against a verified published release.
Loading