No description
Find a file
Ron Smits 280e6a37d9 Initial commit: Gradle platform demo with platform() vs enforcedPlatform()
Multi-module Gradle project demonstrating the difference between
platform() and enforcedPlatform() for BOM dependency management.

- platform-bom: BOM with bcprov-jdk18on:1.78 constraint
- lib-c: library depending on bcprov-jdk18on:1.80 (newer than BOM)
- app-a: consumer using platform() — Gradle picks 1.80 via highest-version
- app-b: consumer using enforcedPlatform() — BOM forces 1.78
2026-04-24 20:50:33 +02:00
app-a Initial commit: Gradle platform demo with platform() vs enforcedPlatform() 2026-04-24 20:50:33 +02:00
app-b Initial commit: Gradle platform demo with platform() vs enforcedPlatform() 2026-04-24 20:50:33 +02:00
gradle/wrapper Initial commit: Gradle platform demo with platform() vs enforcedPlatform() 2026-04-24 20:50:33 +02:00
lib-c Initial commit: Gradle platform demo with platform() vs enforcedPlatform() 2026-04-24 20:50:33 +02:00
platform-bom Initial commit: Gradle platform demo with platform() vs enforcedPlatform() 2026-04-24 20:50:33 +02:00
.gitignore Initial commit: Gradle platform demo with platform() vs enforcedPlatform() 2026-04-24 20:50:33 +02:00
build.gradle.kts Initial commit: Gradle platform demo with platform() vs enforcedPlatform() 2026-04-24 20:50:33 +02:00
gradlew Initial commit: Gradle platform demo with platform() vs enforcedPlatform() 2026-04-24 20:50:33 +02:00
gradlew.bat Initial commit: Gradle platform demo with platform() vs enforcedPlatform() 2026-04-24 20:50:33 +02:00
opencode.json Initial commit: Gradle platform demo with platform() vs enforcedPlatform() 2026-04-24 20:50:33 +02:00
README.md Initial commit: Gradle platform demo with platform() vs enforcedPlatform() 2026-04-24 20:50:33 +02:00
settings.gradle.kts Initial commit: Gradle platform demo with platform() vs enforcedPlatform() 2026-04-24 20:50:33 +02:00

Gradle Platform Demo

Demonstrates the difference between Gradle's platform() and enforcedPlatform() for dependency management.

Structure

Module Purpose
platform-bom BOM defining bcprov-jdk18on:1.78 as a constraint
lib-c Library depending on bcprov-jdk18on:1.80 (newer than BOM — makes the contrast visible at runtime)
app-a Consumer using platform() — BOM version is a recommendation
app-b Consumer using enforcedPlatform() — BOM version is forced

How to Run

Build the project

./gradlew build

Run both apps

./gradlew :app-a:run
./gradlew :app-b:run

Different output, by design:

App Mechanism Runtime output
app-a platform() BouncyCastle registered: version=1.8
app-b enforcedPlatform() BouncyCastle registered: version=1.78

app-a gets 1.80 (runtime shows 1.8) because platform() only adds the BOM constraint to the resolution graph — Gradle's highest-version strategy then picks 1.80 (from lib-c) over 1.78 (from the BOM). The BOM was only a recommendation.

app-b gets 1.78 because enforcedPlatform() overrides any other version declaration — lib-c's transitive 1.80 is forced back down to the BOM's 1.78.

Confirm via dependency insight

app-a (platform()):

./gradlew :app-a:dependencyInsight --dependency bcprov-jdk18on --configuration runtimeClasspath

Output shows 1.80 selected, with the 1.78 constraint from platform-bom listed but not winning — Gradle's highest-version strategy beat the recommendation.

app-b (enforcedPlatform()):

./gradlew :app-b:dependencyInsight --dependency bcprov-jdk18on --configuration runtimeClasspath

Output shows 1.78 selected with Selection reasons: By constraint, Forced — the BOM version is explicitly enforced, overriding the transitive 1.80 from lib-c.

Full dependency trees

./gradlew :app-a:dependencies --configuration runtimeClasspath
./gradlew :app-b:dependencies --configuration runtimeClasspath

Key Takeaway

  • platform() — BOM constraints participate in resolution alongside other versions. Gradle still decides.
  • enforcedPlatform() — BOM constraints override any other version declaration. The BOM is the single source of truth.