Skip to content

Publish thin main jar; move fat jar to shaded classifier#71

Open
stefanhahmann wants to merge 2 commits intozarr-developers:mainfrom
stefanhahmann:attach-shaded-jar-as-classifier
Open

Publish thin main jar; move fat jar to shaded classifier#71
stefanhahmann wants to merge 2 commits intozarr-developers:mainfrom
stefanhahmann:attach-shaded-jar-as-classifier

Conversation

@stefanhahmann
Copy link
Copy Markdown

@stefanhahmann stefanhahmann commented Apr 28, 2026

Summary

The maven-shade-plugin in the pom.xml currently replaces the main artifact with a fat jar and publishes a dependency-reduced POM. Library consumers therefore receive a jar bundling jackson-*, aws-sdk:s3, okhttp, commons-compress, etc., paired with a POM that declares no runtime dependencies.

When a downstream project depends on dev.zarr:zarr-java and also directly on any of those libraries (very common — e.g. Jackson is ubiquitous), maven-enforcer-plugin's duplicate-class / upper-bound-deps rules fail the build because the same classes appear both inside the shaded zarr-java jar and on the regular classpath. There is no clean way for the consumer to exclude them, since the POM hides the bundled coordinates.

Change

Switch the shade execution to attach the fat jar under a classifier rather than replacing the main artifact, and disable the dependency-reduced POM:

   <shadedArtifactAttached>true</shadedArtifactAttached>                                                                                                                                                                                                                                                          
   <shadedClassifierName>shaded</shadedClassifierName>                                                                                                                                                                                                                                                          
   <createDependencyReducedPom>false</createDependencyReducedPom>  

Released artifacts after this change:

artifact contents intended use
zarr-java-.jar only dev.zarr.* classes; full POM with normal library consumers (Maven/Gradle)
zarr-java--shaded.jar fat jar with Main-Class: dev.zarr.zarrjava.cli.Main CLI users (java -jar …-shaded.jar)

CLI users who want the executable jar from Maven Central can pull it with shaded.

Verified locally

   - mvn -DskipTests package produces both jars.                                                                                                                                                                                                                                                                  
   - Thin jar contains only META-INF/ and dev/ (no bundled deps).
   - Shaded jar still has Main-Class: dev.zarr.zarrjava.cli.Main in its manifest.      

Notes / non-goals

  • Native libraries are unaffected: zstd-jni ships its own natives inside its jar (transitively resolved via the thin POM), and blosc-java continues to require the system libblosc library on the host (as already documented in .github/workflows/deploy.yml).
  • No relocations are added. The shaded jar still bundles unrelocated com.fasterxml.jackson etc.; that's fine for the CLI use case and matches today's behavior.

The maven-shade-plugin currently replaces the main artifact with the fat
jar and publishes a dependency-reduced POM. Library consumers therefore
get a jar that bundles Jackson/AWS SDK/okhttp/etc., paired with a POM
that declares no dependencies — which causes duplicate-class failures
under maven-enforcer-plugin's RequireUpperBoundDeps/banDuplicateClasses
when the consumer also depends on those libraries directly.

Switch to shadedArtifactAttached=true with classifier "shaded" and
disable the reduced POM. This publishes:

  - zarr-java-<version>.jar         thin jar, only zarr-java classes;
                                    full POM with proper transitive
                                    dependencies for library consumers.
  - zarr-java-<version>-shaded.jar  fat jar with Main-Class manifest,
                                    for CLI users
                                    (java -jar zarr-java-...-shaded.jar).
@stefanhahmann stefanhahmann marked this pull request as ready for review April 28, 2026 09:03
stefanhahmann added a commit to BioImageTools/ome-zarr-fiji-java that referenced this pull request Apr 29, 2026
The 0.1.3-SNAPSHOT version (zarr-developers/zarr-java#71) is not deployed
to any Maven repository, so each CI workflow now clones the PR branch and
runs `mvn -DskipTests -Dgpg.skip=true install` to populate the local m2
repo before the project build. `gpg.skip` is required because zarr-java's
pom unconditionally signs artifacts during the verify phase.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
stefanhahmann added a commit to BioImageTools/ome-zarr-fiji-java that referenced this pull request Apr 30, 2026
The 0.1.3-SNAPSHOT version (zarr-developers/zarr-java#71) is not deployed
to any Maven repository, so each CI workflow now clones the PR branch and
runs `mvn -DskipTests -Dgpg.skip=true install` to populate the local m2
repo before the project build. `gpg.skip` is required because zarr-java's
pom unconditionally signs artifacts during the verify phase.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@sbesson sbesson left a comment

Choose a reason for hiding this comment

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

Thanks for identifying this regression and opening a fix @stefanhahmann. Indeed, the size of the JAR published to Maven Central exploded in the 0.1.2 release (which arguably should have been released as 0.2.0).

With this PR included, the uberJAR is generated with the -shaded classifier

sbesson@Sebastien-GS-MacBook-Pro-2025 jar-Linux % ls -alh
total 89176
drwx------@  5 sbesson  staff   160B  1 May 16:52 .
drwx------@ 15 sbesson  staff   480B  1 May 16:52 ..
-rw-r--r--@  1 sbesson  staff   1.3M 30 Apr 08:51 zarr-java-0.1.3-SNAPSHOT-javadoc.jar
-rw-r--r--@  1 sbesson  staff    42M 30 Apr 08:51 zarr-java-0.1.3-SNAPSHOT-shaded.jar
-rw-r--r--@  1 sbesson  staff   270K 30 Apr 08:51 zarr-java-0.1.3-SNAPSHOT.jar

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.

2 participants