Chapter 12Lesson 03~155 minutes

Maven Packaging, install, deploy, Distribution Management, Signing, and Repository Publishing: Configuration, Design Choices, and Tradeoffs

Choose deliberately among reactor use and local install, snapshots and immutable releases, project distributionManagement and CI-injected targets, and workstation versus controlled-job signing.

SnapshotsRelease PolicyCI TargetKey CustodyTradeoffs

Publishing policy should minimize accidental authority. This lesson compares designs by asking who controls the coordinate, destination, credentials, and signing key, and what evidence remains after the build.

Learning objectives

  • Choose reactor dependencies over unnecessary local install coupling.
  • Separate snapshot iteration from immutable final releases.
  • Decide when distributionManagement belongs in project policy and when CI should inject a target.
  • Place signing keys at the narrowest controlled release boundary.
  • Connect each decision to reproducibility, security, CI throughput, and upgrade cost.
Current baseline — verified 2026-08-24. Labs use Maven 3.9.16 via Maven Wrapper 3.3.4, JDK 21, Java 17 target, Compiler 3.15.0, JAR 3.5.1, Install/Deploy 3.1.4, Source 3.4.0, Javadoc 3.12.0, Help 3.5.2, and GPG 3.2.8. Publication targets and local Maven repositories are disposable project-relative directories. No real repository, signing key, global settings file, production CI secret, or normal user cache is modified.

1. Reactor relationship versus local install

If two modules are part of one reactor, Maven can order and connect them directly. Installing an upstream module first and then building the downstream module separately creates hidden dependence on mutable workstation/agent state. Use install when a separate build genuinely needs a locally published coordinate; do not use it as a substitute for a reactor edge.

Situation Preferred control Observable reason
Same source tree/reactor Declare the module dependency and build reactor. Reactor graph is visible and does not require prior local installation.
Independent local projects Install to an isolated/local repo when appropriate. Consumer resolves a coordinate outside its reactor; local publication is explicit.
CI promotion Use repository publication/promotion. Agent-local installs do not create an organizational release.

2. Snapshot versus immutable release

A snapshot communicates “this coordinate may advance.” A final version communicates a much stronger contract: consumers and provenance systems can rely on that coordinate continuing to identify the same bytes. Maven can deploy either, but only the repository policy can prevent a final release from being overwritten.

Version Expected repository behavior CI implication
1.2.0-SNAPSHOT Repeated publications allowed; metadata selects timestamp/build instance. Cache/update policy must tolerate change.
1.2.0 Treat coordinate as immutable. A rebuild that changes bytes must use a new version, not overwrite the old release.
Anti-pattern: “same version, new bytes” destroys auditability. Even if a file repository lets you do it, production release repositories should reject or govern redeployment.

3. POM distributionManagement versus CI-injected destination

distributionManagement makes the intended publication identity visible in project metadata. The Deploy Plugin can also accept altDeploymentRepository, whose Maven 3 format is id::url. That is useful when a controlled CI environment must select a disposable or environment-specific destination without editing source.

set -euo pipefail
./mvnw -Dmaven.repo.local=.ci-m2 deploy   -DaltDeploymentRepository="ci-lab::file://$PWD/.ci-publication"

Whichever mechanism you choose, the repository ID is still part of credential selection. Avoid hiding the destination in an opaque wrapper script with no logged policy context.

4. Developer signing versus controlled release-job signing

Developer signing is convenient for personal artifacts but spreads key custody and makes automation inconsistent. A controlled release job can narrow access, produce auditable logs, and use short-lived/agent-backed credentials. The release job must still avoid echoing passphrases or exporting private keys into artifacts.

Model Benefit Risk / cost
Developer workstation key Interactive and simple for small projects. Many endpoints hold release authority; difficult central audit/rotation.
Dedicated release job/agent Narrower authority, repeatable policy, centralized audit. Requires secure secret/key service integration and job hardening.
Disposable training key Safe for learning signature mechanics. Has no production identity value; must never be confused with organizational trust.

5. Source/Javadoc artifacts: interoperability versus release cost

Sources and Javadocs improve IDE navigation, debugging, and downstream documentation. They also expand the publication set that must be built, checked, signed, and kept consistent. Treat them as intentional attached artifacts: pin plugin versions, generate them before install/deploy, and verify that all classifiers share the intended coordinate/version.

6. Build once, promote the same identity

The safest promotion model records at least source revision, project version, artifact digest, build-tool/JDK identity, and test/gate evidence. A later stage promotes the exact artifact rather than reconstructing it from source under potentially different tools or timestamps. Maven can rebuild deterministically with proper controls, but “rebuild later and assume equivalence” is a weaker release invariant than “promote the same bytes.”

7. Worked decision table

Decision Default recommendation When to deviate
Same-repo module needs sibling Reactor dependency, not prior install. Separate build boundary is intentional and tested.
Development iteration Snapshot coordinate. Use unique prerelease versions if your release governance forbids snapshots.
Production release Immutable final version. Never overwrite without an explicit exceptional governance process.
Destination policy Visible project intent + controlled CI override where necessary. Central platform may intentionally own all deploy destinations.
Signing authority Controlled release environment. Small/personal projects may accept workstation keys with documented custody.
Attached docs/sources Publish when consumers benefit and policy requires. Internal minimal artifacts may omit them if tooling/contracts do not need them.

8. Keep neighboring systems distinct

Maven controls build and publication mechanics. A repository manager controls retention, immutability, staging, cleanup, and access policy. CI controls job identity and secret injection. GPG/key infrastructure controls signing identity. The JDK/toolchain controls compilation. IDE upload buttons are merely alternative clients and must not bypass these policies.

9. Performance: measure the right phase

Publishing time is usually small compared with dependency resolution, compile, test, Javadoc generation, or network transfer, but attached artifacts and signing can add work. Measure cold versus warm resolution separately from source/Javadoc generation and repository upload. Do not remove verification or signing merely because one release job is slow; find the actual expensive phase first.

Knowledge check

Why is a reactor dependency usually better than “install library, then build app” inside one repository?

What must change when release bytes change after 1.0.0 is published?

Does altDeploymentRepository remove the need for repository IDs?

Why prefer controlled-job signing for organizational releases?

Is a repository manager configuration part of Maven project configuration?

10. Bridge to failure diagnosis

Lesson 4 deliberately breaks the boundaries above: wrong credential ID, mutable final coordinate, leaked command-line credential shape, unsafe key placement, and stale local installs. The goal is to diagnose from evidence without deleting normal caches or hiding the first failure.

Official references and version notes

Version-sensitive statements were checked against Apache Maven primary documentation on 2026-08-24. The mandatory Maven path pins Maven 3.9.16 via Maven Wrapper 3.3.4, JDK 21 to run Maven, Java 17 as the compiler release target, Compiler Plugin 3.15.0, JAR Plugin 3.5.1, Install Plugin 3.1.4, Deploy Plugin 3.1.4, Source Plugin 3.4.0, Javadoc Plugin 3.12.0, Help Plugin 3.5.2, and GPG Plugin 3.2.8.

Maven 4 remains preview-stage in the current Apache download page, so this chapter does not silently switch publishing semantics to Maven 4.

The Deploy Plugin 3.1.4 documents the Maven 3 alternative-repository format as id::url; the older three-part Maven 2 syntax must not be copied into current instructions.

Keep the academy open

Support free, practical DevOps education.

Every lesson is designed to remain readable in a browser, downloadable from GitHub, and usable without a paid learning platform. Contributions help expand and maintain the curriculum.

Ethereum / ERC-20
0x716c4Ab160C4B66F31a28AE2448BfF68fc3a2ef0 Send only Ethereum/ERC-20 compatible assets to this address.