Skip to content

build: add Implementation-Version to packaged jars - #4884

Closed
jabrailkhalil wants to merge 1 commit into
kroxylicious:mainfrom
jabrailkhalil:build/implementation-version-metadata
Closed

jabrailkhalil wants to merge 1 commit into
kroxylicious:mainfrom
jabrailkhalil:build/implementation-version-metadata

Conversation

@jabrailkhalil

@jabrailkhalil jabrailkhalil commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds Implementation-Title, Implementation-Version, and Implementation-Vendor manifest entries to every packaged jar, sourced from the module's effective POM via maven-jar-plugin's addDefaultImplementationEntries.

Closes #4666

Changes

  • pom.xml (parent): configured maven-jar-plugin in <pluginManagement> with <addDefaultImplementationEntries>true</addDefaultImplementationEntries>. Aggregator (pom packaging) modules never invoke the jar plugin, so this is harmless to them.
  • kroxylicious-api/pom.xml: enables the failsafe plugin so an integration test can assert on the packaged jar (it runs after the package phase).
  • kroxylicious-api/.../ImplementationVersionIT.java: three checks:
    • the packaged jar's manifest carries the expected Implementation-* entries;
    • Class.getPackage().getImplementationVersion() returns the project version for a class loaded from the jar;
    • the test-classpath context (classes dir) has no implementation version, documenting the null read there.

Verification

Local build (JDK 21, Maven 3.9.11):

mvn -pl kroxylicious-api -am verify -DskipUTs=true
  • BUILD SUCCESS, failsafe ran ImplementationVersionIT with 3 tests, 0 failures.
  • jar:3.5.1:jar produced kroxylicious-api-0.25.0-SNAPSHOT.jar whose manifest contains:
    Implementation-Version: 0.25.0-SNAPSHOT, Implementation-Title: Kroxylicious API, Implementation-Vendor: Kroxylicious.

Note: the full unit suite was not runnable on this Windows host because the pre-existing UtilsTest#testFileAsStringNamedPipe requires mkfifo (Linux-only; unaffected by this change).

Commits are signed off and carry an Assisted-by: trailer per AGENTS.md.

@jabrailkhalil
jabrailkhalil requested a review from a team as a code owner September 10, 2026 18:57
@sonarqubecloud

Copy link
Copy Markdown

@sonarqubecloud

Copy link
Copy Markdown

* as {@code Implementation-Version}. These integration tests run after the jar is packaged
* and assert on the real manifest.
*/
class ImplementationVersionIT {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice instinct adding coverage here — declarative Maven config changes like this are easy to leave unverified. One thing worth being explicit about in the class Javadoc or PR description: these tests verify that maven-jar-plugin and the JVM behave as documented (i.e. that the config was wired correctly), not any Kroxylicious-owned logic. That's still useful — it'd catch a scope/POM-inheritance mistake — but it's a different kind of guarantee than testing our own code, and worth naming so a future reader doesn't read it as "our version-reporting logic is tested" when what's actually pinned down is Maven's own contract.

@k-wall k-wall Sep 11, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to adding a test, however, I've got an alternative test approach to suggest to you both.

https://github.com/jabrailkhalil/kroxylicious/pull/1/changes

Instead on adding a new IT test, let's give the lint workflow the responsibility to check that the JARs metadata in in the right shape. It already checks POM metadata - so the new responsibility is in keeping.

The POC tests kroxylicious-api.jar. We could extend it to check all the other shippable JARs. I'm not sure I'd go quite that far. Checking one JAR is enough for me.

If we like the idea, I suggest merging into your @jabrailkhalil PR, and removing the IT test.

WDYAT?

private static final String EXPECTED_VERSION = System.getProperty("implementation.version");

private Path packagedJar() {
return Path.of("target", "kroxylicious-api-" + EXPECTED_VERSION + ".jar");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This re-derives the packaged jar's filename ("target" + artifactId + version) by hand, duplicating naming knowledge the POM already owns. If finalName or the output directory is ever customized in kroxylicious-api/pom.xml, this will silently drift out of sync. I'd rather the POM hand the test the fully-resolved path directly, e.g. ${project.build.directory}/${project.build.finalName}.jar as a system property, than have the test reconstruct Maven's naming convention itself.


@Test
void packagedJarManifestCarriesImplementationEntries() throws Exception {
try (var jarFile = new JarFile(packagedJar().toFile())) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will fail with a raw FileNotFoundException if the jar hasn't been packaged yet — for example if this IT is somehow invoked before the package phase, target/ is stale/cleaned, or the version property resolves to something unexpected. Suggest guarding with assumeThat(packagedJar()).exists() before opening the jar, so a missing artifact skips the test with a clear explanation rather than failing on an opaque exception. Same guard would help the URLClassLoader test below (line 47), which hits the same packagedJar() path.

k-wall added a commit to k-wall/kroxylicious that referenced this pull request Sep 11, 2026
Add a Python script to validate JAR manifest implementation entries
and integrate it into the lint workflow as a proof of concept for
the kroxylicious-api module.

This provides an alternative to the integration test approach in PR kroxylicious#4884,
validating build artifacts directly during the lint phase similar to how
we validate POM metadata.

The script validates that maven-jar-plugin's addDefaultImplementationEntries
correctly populates Implementation-Title, Implementation-Version, and
Implementation-Vendor in the JAR manifest.

Related: kroxylicious#4884

Assisted-by: Claude Sonnet 4.5 <[email protected]>
Signed-off-by: Keith Wall <[email protected]>
@k-wall

k-wall commented Sep 11, 2026

Copy link
Copy Markdown
Member

@jabrailkhalil thanks for picking up this work. it is appreciated. you'll need put the DCO signoff on your commit(s) too.

@jabrailkhalil
jabrailkhalil force-pushed the build/implementation-version-metadata branch from 5fd6cde to 486b97c Compare September 11, 2026 11:07
Configure maven-jar-plugin to add the default implementation manifest entries and validate the packaged kroxylicious-api JAR in the existing lint workflow. The validation checks the exact Maven finalName artifact and keeps packaging-contract verification out of the runtime test suite.

Assisted-by: ChatGPT GPT-5.6 Sol
Co-authored-by: Keith Wall <[email protected]>
Signed-off-by: Keith Wall <[email protected]>
Signed-off-by: jabrailkhalil <[email protected]>
Signed-off-by: Jabrail <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Populate Implementation-Version in JAR manifests via parent pom

3 participants