You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Gradle] Configure transitive dependencies via ComponentMetadataRules (#134169) (#134710)
This introduces ComponentMetadataRulesPlugin that contains declarative logic for dealing with transitive dependencies on a per dependency level.
Ulitmately we want more finegrained control over our dependencies without loosing information about transitive dependencies.
The initial list of the applied component metadata rules will be more finegrained over time. Initially this is mostly a reflection of how we brought in dependencies before by basically making the transitive dependencies we identified as required where added as direct dependency.
I started looking through the existing dependencies applyging the following pattern:
if no problematic transitive dependency detected, do not apply any component meta data rule.
if only non group dependencies have been problematic, use ExcludeOtherGroupsTransitiveRule which allows transitive dependencies brought with the same groupId as the parent but excludes all others.
Otherwise exclude all transitive dependencies by applying ExcludeAllTransitivesRule
We will add more specific rules in the future as we see the need to "fix' component metadata of thirdparty dependencies.
This change replaces our plain transitive = false approach for non elasticsearch dependencies
Historically we have solved dealing with transitive dependencies and component metadata in this regard by just ignoring it and bringing in dependencies explicitly. This results in
weaker control what we bring in and why
loose information why a dependency is needed and how its tight ot another dependency on the classpath
transitive behavior differed in different context as we only have applied transitivity
Furthermore the way we have configured transitive = false for each dependency resulted in other problems when using other newer Gradle APIs like test suites.
Copy file name to clipboardExpand all lines: BUILDING.md
+64Lines changed: 64 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -97,6 +97,70 @@ will have the `origin` attribute been set to `Generated by Gradle`.
97
97
> If you want to add a level of verification you can manually confirm the checksum (e.g. by looking it up on the website of the library)
98
98
> Please replace the content of the `origin` attribute by `official site` in that case.
99
99
100
+
##### Handling transitive dependencies
101
+
102
+
Dependency management is a critical aspect of maintaining a secure and reliable build system, requiring explicit control over what we rely on. The Elasticsearch build mainly uses component metadata rules declared in the `ComponentMetadataRulesPlugin`
103
+
plugin to manage transitive dependencies and avoid version conflicts.
104
+
This approach ensures we have explicit control over all dependencies used in the build.
105
+
106
+
###### General Guidelines
107
+
108
+
1.**Avoid unused transitive dependencies** - Dependencies that are not actually used by our code should be excluded to reduce the attack surface and avoid potential conflicts.
109
+
110
+
2.**Prefer versions declared in `build-tools-internal/version.properties`** - All dependency versions should be centrally managed in this file to ensure consistency across the entire build.
111
+
112
+
3.**Libraries required to compile our code should be direct dependencies** - If we directly use a library in our source code, it should be declared as a direct dependency rather than relying on it being transitively available.
113
+
114
+
###### Component Metadata Rules
115
+
116
+
We use two main types of component metadata rules at this point to manage transitive dependencies:
117
+
118
+
-**`ExcludeAllTransitivesRule`** - Excludes all transitive dependencies for libraries where we want complete control over dependencies or the transitive dependencies are unused.
119
+
120
+
-**`ExcludeOtherGroupsTransitiveRule`** - Excludes transitive dependencies that don't belong to the same group as the direct dependency, while keeping same-group dependencies.
121
+
-
122
+
-**`ExcludeByGroup`** - Excludes transitive dependencies that match a specific groupId while keeping all other transitive dependencies with different groupIds.
123
+
124
+
Examples from the `ComponentMetadataRulesPlugin`:
125
+
126
+
```gradle
127
+
// Exclude all transitives - used when transitive deps are unused or problematic
Copy file name to clipboardExpand all lines: build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/ElasticsearchJavaModulePathPlugin.java
0 commit comments