@groovy.transform.CompileStatic class BomManagedVersions extends java.lang.Object
Lightweight replacement for the Spring Dependency Management plugin's version property override feature.
Parses BOM POM files to determine the version every managed artifact
resolves to, both with the BOM's default <properties> values and
with the project's overrides applied (via ext['property.name'] in
build.gradle or via gradle.properties). Any artifact whose
effective version differs from the BOM default becomes a version override.
Overrides are applied as strict dependency constraints
(see applyTo(DependencyHandler, String)). A strict constraint wins
over the require constraints contributed by Gradle's native
platform() mechanism, so an override is honored even when it
downgrades a managed version - a plain
ResolutionStrategy.eachDependency() / useVersion() hook
would lose to the platform's higher version during conflict resolution.
Because the effective version is computed by re-resolving imported
(<scope>import</scope>) BOMs with the project's property overrides
applied, overriding a property that selects an imported BOM's version
(for example spring-boot.version) re-imports that BOM and pulls in
its updated managed-dependency set.
POMs are parsed with Maven's own org.apache.maven:maven-model
library (MavenXpp3Reader into a Model) so that parent-POM
inheritance, <properties> extraction and <scope>import</scope>
resolution mirror upstream Maven rather than a bespoke XML approximation.
Each POM's <properties> are scoped to that POM (and its parents),
matching Maven's model rather than leaking property values across unrelated
imported BOMs.
Gradle's native platform() mechanism handles the base BOM import
and default version management. This class only adds the one feature Gradle
lacks: property-based version customization
(see Gradle #9160).
This is the underlying utility used by the
org.apache.grails.gradle.bom-property-overrides plugin
(registered in grails-gradle-plugins). It is BOM-agnostic and
can be used directly with any BOM that follows the Maven
<properties> convention for managed versions.
| Constructor and description |
|---|
BomManagedVersions() |
| Type Params | Return Type | Name and description |
|---|---|---|
|
void |
applyTo(DependencyHandler dependencies, java.lang.String configurationName)Applies the detected version overrides to the given configuration as strict dependency constraints. |
|
java.util.Map<java.lang.String, java.lang.String> |
getOverrides()Returns an unmodifiable view of the version overrides. |
|
boolean |
hasOverrides()Returns whether any version overrides were detected. |
|
static void |
parseBomFile(java.io.File pomFile, java.util.Map<java.lang.String, java.lang.String> bomProperties, java.util.Map<java.lang.String, java.util.List<java.lang.String>> propertyToArtifacts)Parses a BOM POM file and extracts the property-to-artifact mapping. |
|
static BomManagedVersions |
resolve(ConfigurationContainer configurations, DependencyHandler dependencies, java.util.function.Function<java.lang.String, java.lang.String> propertyLookup, java.lang.String bomCoordinates)Resolves a single BOM via captured Gradle services rather than a Project reference. |
|
static BomManagedVersions |
resolve(ConfigurationContainer configurations, DependencyHandler dependencies, java.util.function.Function<java.lang.String, java.lang.String> propertyLookup, java.util.Collection<java.lang.String> bomCoordinatesList)Resolves multiple BOMs via captured Gradle services. |
|
static BomManagedVersions |
resolve(Project project, java.lang.String bomCoordinates)Convenience overload that captures services from the given Project. |
|
static BomManagedVersions |
resolve(Project project, java.util.Collection<java.lang.String> bomCoordinatesList)Convenience overload that captures services from the given Project. |
| Methods inherited from class | Name |
|---|---|
class java.lang.Object |
java.lang.Object#equals(java.lang.Object), java.lang.Object#getClass(), java.lang.Object#hashCode(), java.lang.Object#notify(), java.lang.Object#notifyAll(), java.lang.Object#toString(), java.lang.Object#wait(), java.lang.Object#wait(long), java.lang.Object#wait(long, int) |
Applies the detected version overrides to the given configuration as strict dependency constraints.
Strict constraints are used deliberately: a plain platform()
contributes require constraints, and a soft override (e.g.
useVersion()) would lose to a higher require version
during conflict resolution. A strict constraint overrides require,
so the project's chosen version wins in both directions (upgrade and
downgrade).
dependencies - the project's dependency handlerconfigurationName - the name of the configuration to add constraints to Returns an unmodifiable view of the version overrides.
Keys are group:artifact, values are the override version strings.
Returns whether any version overrides were detected.
Parses a BOM POM file and extracts the property-to-artifact mapping. This method does not follow imported BOMs (or parent POMs) recursively - it only processes the given file. Intended for testing and direct POM inspection.
pomFile - the BOM POM file to parsebomProperties - output map to receive property name to default value mappingspropertyToArtifacts - output map to receive property name to artifact coordinate mappings Resolves a single BOM via captured Gradle services rather than a
Project reference. Preferred for config-cache discipline:
callers capture services once (typically inside a single
afterEvaluate block) and never leak a Project
reference into the override map that lives on past configuration time.
configurations - the project's configuration container, captured at apply/afterEvaluate timedependencies - the project's dependency handler, captured at apply/afterEvaluate timepropertyLookup - function returning the project's property value as a String, or null if unsetbomCoordinates - the BOM coordinates in group:artifact:version format Resolves multiple BOMs via captured Gradle services. The result is a
plain data carrier (a Map<String, String> of version overrides
inside BomManagedVersions) that holds no Project
reference, so it can be safely captured by per-configuration
constraint declarations and survive configuration-cache serialization.
The override set is computed as the difference between two resolutions of the BOM tree: one using the BOM's default property values, and one using the project's property overrides. Any managed artifact whose effective version differs from its default version is recorded as an override.
configurations - the project's configuration container, captured at apply/afterEvaluate timedependencies - the project's dependency handler, captured at apply/afterEvaluate timepropertyLookup - function returning the project's property value as a String, or null if unsetbomCoordinatesList - list of BOM coordinates in group:artifact:version formatConvenience overload that captures services from the given Project. Production callers should prefer the services-based overload above so the resolve path never sees a Project reference. This overload is primarily useful for tests and ad-hoc usage.
project - the Gradle project (services are extracted at call time)bomCoordinates - the BOM coordinates in group:artifact:version formatConvenience overload that captures services from the given Project. Production callers should prefer the services-based overload above so the resolve path never sees a Project reference. This overload is primarily useful for tests and ad-hoc usage.
project - the Gradle project (services are extracted at call time)bomCoordinatesList - list of BOM coordinates in group:artifact:version format