Course contentsShow
← Java
Lesson 2511 of 2,87047. Java Platform Module System (JPMS)Free lesson

Module Versioning in Modular JARs

Adding version information to module descriptors and understanding how versions are expressed in JPMS.

Module Versioning in Modular JARs

You'll learn how to add and express version information in JPMS module descriptors.

While the Java Platform Module System focuses primarily on structural dependencies (what modules require what), it also provides a way to attach version metadata to your modules. This version information doesn't affect module resolution at compile or runtime—JPMS doesn't perform automatic version checking—but it's invaluable for documentation, tooling, and human understanding of which module version you're working with.

Adding Version Information

Version data is added to a modular JAR using the --module-version option when creating the JAR:

jar --create --file mylib.jar --module-version=2.1.0 -C out/mylib .

This embeds the version string 2.1.0 into the JAR's metadata. You cannot specify version directly in module-info.java—it's a packaging concern, not a compilation concern.

How Versions Are Expressed

JPMS doesn't mandate a specific version format. You can use semantic versioning (1.2.3), date-based versions (2024.01), or any string. However, Maven/semantic versioning conventions are strongly recommended for clarity:

  • MAJOR.MINOR.PATCH (e.g., 3.2.1)
  • Optional pre-release identifiers (e.g., 1.0.0-beta)

Inspecting Module Versions

You've already learned jar --describe-module to inspect modular JARs. When a version is present, it appears in the output:

com.example.mylib@2.1.0

The ModuleDescriptor API can also retrieve this version programmatically at runtime, useful for logging or diagnostics.

Think of It Like a Label

Version information in JPMS is like a label on a shipping box: it tells you what version is inside, but the system doesn't enforce compatibility rules based on it. External tools (Maven, Gradle) handle version conflict resolution.

Key Takeaway: Module versions are added via --module-version when creating JARs, provide metadata for tooling and humans, but JPMS itself does not enforce version-based dependency resolution.