-
Notifications
You must be signed in to change notification settings - Fork 17
Add optional filtering of published dependency constraints to used dependencies only #1420
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
Generate changelog in
|
lockFileConstraints in gradle module metadata and POMs
lockFileConstraints in gradle module metadata and POMs
✅ Successfully generated changelog entry!What happened?Your changelog entries have been stored in the database as part of our migration to ChangelogV3. Need to regenerate?Simply interact with the changelog bot comment again to regenerate these entries. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds an opt-in feature to filter published dependency constraints to only include dependencies that are actually used by the component being published. The goal is to reduce metadata bloat in POMs and Gradle Module Metadata while maintaining backwards compatibility.
Key changes:
- Introduces
com.palantir.gradle.versions.filterLockFileConstraintsproperty to enable constraint filtering - Filters constraints by resolving compile and runtime classpaths to determine used modules
- Adds comprehensive test coverage for both filtered and unfiltered scenarios with and without local constraints
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| VersionsLockPlugin.java | Implements the core filtering logic using classpath resolution and adds the configuration property |
| VersionsLockPluginIntegrationSpec.groovy | Adds extensive test cases covering all combinations of filtering and local constraint settings |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
src/test/groovy/com/palantir/gradle/versions/VersionsLockPluginIntegrationSpec.groovy
Outdated
Show resolved
Hide resolved
src/main/java/com/palantir/gradle/versions/VersionsLockPlugin.java
Outdated
Show resolved
Hide resolved
…nIntegrationSpec.groovy Co-authored-by: Copilot <[email protected]>
|
Example: build.gradle dependencies {
implementation project(':environment-variables')
implementation gradleApi()
api project(':providers')
annotationProcessor 'org.immutables:value'
compileOnly 'org.immutables:value::annotations'
testImplementation 'org.assertj:assertj-core'
testImplementation 'org.junit.jupiter:junit-jupiter'
testImplementation 'com.netflix.nebula:nebula-test'
}Before: "dependencyConstraints": [
{
"group": "com.fasterxml.jackson.core",
"module": "jackson-annotations",
"version": {
"requires": "2.19.2"
},
"reason": "Computed from com.palantir.consistent-versions' versions.lock in gradle-utils"
},
{
"group": "com.gradle",
"module": "develocity-gradle-plugin-adapters",
"version": {
"requires": "1.2.1"
},
"reason": "Computed from com.palantir.consistent-versions' versions.lock in gradle-utils"
},
{
"group": "org.apache.commons",
"module": "commons-lang3",
"version": {
"requires": "3.18.0"
},
"reason": "Computed from com.palantir.consistent-versions' versions.lock in gradle-utils"
},
{
"group": "org.immutables",
"module": "value",
"version": {
"requires": "2.11.3"
},
"reason": "Computed from com.palantir.consistent-versions' versions.lock in gradle-utils"
}
],After "dependencyConstraints": [
{
"group": "org.immutables",
"module": "value",
"version": {
"requires": "2.11.3"
},
"reason": "Computed from com.palantir.consistent-versions' versions.lock in gradle-utils"
}
], |
…-consistent-versions into finlayw/enable_filtering
| .addAllLater(maybeFilterConstraintsByUsage(subproject, lockFileConstraints)); | ||
| }); | ||
|
|
||
| subproject |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to make the default behaviour not publishing the dep constraints at all?
Before this PR
Background: https://pl.ntr/2wT
The
gradle-consistent-versionsplugin currently publishes all constraints fromversions.lockin component metadata (POMsand Gradle Module Metadata), even for dependencies that aren't actually used by the published component. This causes:<dependencyManagement>section includes irrelevant dependencies, confusing users who may think these are actual dependenciesdependencyManagementis mostly ignored, Gradle Module Metadata applies these constraints by default, potentially affecting dependency resolution unnecessarilyAfter this PR
This PR introduces an opt-in property
com.palantir.gradle.versions.filterLockFileConstraintsthat, when enabled, filters published constraints to only include dependencies in the actual transitive closure of the component being published.filterLockFileConstraints=true, the plugin resolves the compile and runtime classpaths to determine which modules are actually usedcom.palantir.gradle.versions.publishLocalConstraints) continue to work as beforeThis filtering capability previously existed (#191) but was removed due to performance concerns (#504). By making this opt-in, projects can choose between:
==COMMIT_MSG==
Add optional filtering of published dependency constraints
Introduces
com.palantir.gradle.versions.filterLockFileConstraintsproperty to filter published constraints to only include dependencies actually used by the component, reducing metadata bloat while maintaining backwards compatibility as an opt-in feature.==COMMIT_MSG==
Possible downsides?