Class BomResolverService
- All Implemented Interfaces:
org.gradle.api.services.BuildService<org.gradle.api.services.BuildServiceParameters.None>
This service addresses the issue where multiple subprojects attempting to resolve
BOM configurations simultaneously in parallel builds with Gradle 9+ would cause
IllegalResolutionException due to exclusive lock conflicts.
The service works by:
- Eagerly resolving BOMs during the configuration phase when exclusive locks are available
- Caching resolved recommendations indexed by BOM coordinates
- Providing cached results during dependency resolution phase to avoid lock conflicts
- Supporting full Maven model building with property interpolation and parent POM resolution
Thread-safe implementation using ConcurrentHashMap and synchronized blocks
to handle concurrent access from multiple projects in parallel builds.
- Since:
- 13.1.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoideagerlyResolveAndCacheBoms(org.gradle.api.Project project, String configName) Eagerly resolves and caches BOM recommendations during the configuration phase.getCachedRecommendationsFromConfiguration(org.gradle.api.artifacts.Configuration configuration, Set<String> reasons) Retrieves cached BOM recommendations from a configuration.getRecommendations(org.gradle.api.Project project, String configName, Set<String> reasons) Retrieves BOM recommendations for a given project configuration.getRecommendationsFromConfiguration(org.gradle.api.artifacts.Configuration configuration, org.gradle.api.Project project, Set<String> reasons) Resolves BOM recommendations from a configuration with full Maven model building.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.gradle.api.services.BuildService
getParameters
-
Constructor Details
-
BomResolverService
public BomResolverService()
-
-
Method Details
-
getRecommendations
public Map<String,String> getRecommendations(org.gradle.api.Project project, String configName, Set<String> reasons) Retrieves BOM recommendations for a given project configuration.This method first attempts to return cached recommendations. If not cached, it falls back to direct resolution. This is the main entry point for accessing BOM recommendations from the build service.
- Parameters:
project- the Gradle project requesting recommendationsconfigName- the name of the configuration containing BOM dependenciesreasons- a mutable set that will be populated with reasons explaining why specific recommendations were applied- Returns:
- a map of dependency coordinates (groupId:artifactId) to recommended versions
- Throws:
RuntimeException- if BOM resolution fails
-
getCachedRecommendationsFromConfiguration
public Map<String,String> getCachedRecommendationsFromConfiguration(org.gradle.api.artifacts.Configuration configuration, Set<String> reasons) Retrieves cached BOM recommendations from a configuration.This method first checks if recommendations have been cached for the given configuration. If cached, returns the cached result. If not cached, throws an exception indicating that the BOM was not pre-resolved.
This design ensures that all BOM resolution happens during the configuration phase via
eagerlyResolveAndCacheBoms(Project, String), preventing configuration resolution during the dependency resolution phase.- Parameters:
configuration- the Gradle configuration containing BOM dependenciesreasons- a mutable set that will be populated with cached reasons- Returns:
- cached BOM recommendations as a map of coordinates to versions
- Throws:
RuntimeException- if the BOM was not pre-resolved and cached
-
eagerlyResolveAndCacheBoms
Eagerly resolves and caches BOM recommendations during the configuration phase.This method should be called during the configuration phase (typically in
afterEvaluate) when exclusive locks are available. It resolves all BOMs in the specified configuration and caches the results for later use.If resolution fails, empty results are cached to prevent repeated failures and ensure the build can continue.
- Parameters:
project- the Gradle project containing the BOM configurationconfigName- the name of the configuration containing BOM dependencies
-
getRecommendationsFromConfiguration
public Map<String,String> getRecommendationsFromConfiguration(org.gradle.api.artifacts.Configuration configuration, org.gradle.api.Project project, Set<String> reasons) Resolves BOM recommendations from a configuration with full Maven model building.This method performs the actual work of resolving BOM files, parsing them with full Maven model support (including parent POM resolution and property interpolation), and caching the results. It uses synchronization to prevent concurrent resolution of the same BOM.
- Parameters:
configuration- the Gradle configuration containing BOM dependenciesproject- the Gradle project (used for Maven model interpolation and resolution)reasons- a mutable set that will be populated with resolution reasons- Returns:
- a map of dependency coordinates to recommended versions
- Throws:
RuntimeException- if BOM resolution or parsing fails
-