-
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?
Changes from 6 commits
0226d00
8e11a7e
7882acd
7e1a7b0
169a63b
5596b28
18aa028
e803374
da10848
dfcc623
d04ec34
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -922,10 +922,118 @@ class VersionsLockPluginIntegrationSpec extends IntegrationSpec { | |
| gradleVersionNumber << GRADLE_VERSIONS | ||
| } | ||
|
|
||
| def "#gradleVersionNumber: published constraints are derived from lock file (with local constraints)"() { | ||
| def "#gradleVersionNumber: published constraints are derived from lock file (with local constraints and with filtering)"() { | ||
| setup: | ||
| // Test with local constraints enabled | ||
| file('gradle.properties') << 'com.palantir.gradle.versions.publishLocalConstraints = true' | ||
| file('gradle.properties') << ''' | ||
| com.palantir.gradle.versions.publishLocalConstraints = true | ||
| com.palantir.gradle.versions.filterLockFileConstraints = true | ||
| ''' | ||
| gradleVersion = gradleVersionNumber | ||
|
|
||
| buildFile << """ | ||
| allprojects { | ||
| apply plugin: 'java' | ||
| } | ||
| """.stripIndent(true) | ||
|
|
||
| String publish = """ | ||
| apply plugin: 'maven-publish' | ||
| group = 'com.palantir.published-constraints' | ||
| version = '1.2.3' | ||
| publishing.publications { | ||
| maven(MavenPublication) { | ||
| from components.java | ||
| } | ||
| } | ||
| """.stripIndent(true) | ||
|
|
||
| addSubproject('foo', """ | ||
| $publish | ||
| dependencies { | ||
| implementation 'ch.qos.logback:logback-classic:1.2.3' | ||
| } | ||
| """.stripIndent(true)) | ||
|
|
||
| addSubproject('bar', """ | ||
| $publish | ||
| dependencies { | ||
| implementation 'junit:junit:4.10' | ||
| } | ||
| """.stripIndent(true)) | ||
|
|
||
| if (GradleVersion.version(gradleVersionNumber) < GradleVersion.version("6.0")) { | ||
| settingsFile << """ | ||
| enableFeaturePreview('GRADLE_METADATA') | ||
| """.stripIndent(true) | ||
| } | ||
|
|
||
| runTasks('--write-locks') | ||
|
|
||
| when: | ||
| runTasks('generatePomFileForMavenPublication', 'generateMetadataFileForMavenPublication') | ||
|
|
||
| def junitDep = new MetadataFile.Dependency( | ||
| group: 'junit', | ||
| module: 'junit', | ||
| version: [requires: '4.10']) | ||
| def logbackDep = new MetadataFile.Dependency( | ||
| group: 'ch.qos.logback', | ||
| module: 'logback-classic', | ||
| version: [requires: '1.2.3']) | ||
| def slf4jDep = new MetadataFile.Dependency( | ||
| group: 'org.slf4j', | ||
| module: 'slf4j-api', | ||
| version: [requires: '1.7.25']) | ||
| def fooDep = new MetadataFile.Dependency( | ||
| group: 'com.palantir.published-constraints', | ||
| module: 'foo', | ||
| version: [requires: '1.2.3']) | ||
| def barDep = new MetadataFile.Dependency( | ||
| group: 'com.palantir.published-constraints', | ||
| module: 'bar', | ||
| version: [requires: '1.2.3']) | ||
|
|
||
| then: "foo's metadata file has the right dependency constraints" | ||
| def fooMetadataFilename = new File(projectDir, "foo/build/publications/maven/module.json") | ||
| def fooMetadata = new ObjectMapper().readValue(fooMetadataFilename, MetadataFile) | ||
|
|
||
| fooMetadata.variants == [ | ||
| new MetadataFile.Variant( | ||
| name: 'runtimeElements', | ||
| dependencies: [logbackDep], | ||
| dependencyConstraints: [barDep, logbackDep, slf4jDep]), | ||
| new MetadataFile.Variant( | ||
| name: 'apiElements', | ||
| dependencies: null, | ||
| dependencyConstraints: [barDep, logbackDep, slf4jDep]) | ||
| ] as Set | ||
|
|
||
| and: "bar's metadata file has the right dependency constraints" | ||
| def barMetadataFilename = new File(projectDir, "bar/build/publications/maven/module.json") | ||
| def barMetadata = new ObjectMapper().readValue(barMetadataFilename, MetadataFile) | ||
|
|
||
| barMetadata.variants == [ | ||
| new MetadataFile.Variant( | ||
| name: 'runtimeElements', | ||
| dependencies: [junitDep], | ||
| dependencyConstraints: [fooDep, junitDep]), | ||
| new MetadataFile.Variant( | ||
| name: 'apiElements', | ||
| dependencies: null, | ||
| dependencyConstraints: [fooDep, junitDep]), | ||
| ] as Set | ||
|
|
||
| where: | ||
| gradleVersionNumber << GRADLE_VERSIONS | ||
| } | ||
|
|
||
| def "#gradleVersionNumber: published constraints are derived from lock file (with local constraints and without filtering)"() { | ||
| setup: | ||
| // Test with local constraints enabled | ||
| file('gradle.properties') << ''' | ||
| com.palantir.gradle.versions.publishLocalConstraints = true | ||
| ''' | ||
| gradleVersion = gradleVersionNumber | ||
|
|
||
| buildFile << """ | ||
|
|
@@ -1025,7 +1133,102 @@ class VersionsLockPluginIntegrationSpec extends IntegrationSpec { | |
| gradleVersionNumber << GRADLE_VERSIONS | ||
| } | ||
|
|
||
| def "#gradleVersionNumber: published constraints are derived from lock file (without local constraints)"() { | ||
| def "#gradleVersionNumber: published constraints are derived from lock file (without local constraints and with filtering)"() { | ||
| setup: | ||
| // Test with local constraints enabled | ||
FinlayRJW marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| file('gradle.properties') << 'com.palantir.gradle.versions.filterLockFileConstraints = true' | ||
| gradleVersion = gradleVersionNumber | ||
|
|
||
| buildFile << """ | ||
| allprojects { | ||
| apply plugin: 'java' | ||
| } | ||
| """.stripIndent(true) | ||
|
|
||
| String publish = """ | ||
| apply plugin: 'maven-publish' | ||
| group = 'com.palantir.published-constraints' | ||
| version = '1.2.3' | ||
| publishing.publications { | ||
| maven(MavenPublication) { | ||
| from components.java | ||
| } | ||
| } | ||
| """.stripIndent(true) | ||
|
|
||
| addSubproject('foo', """ | ||
| $publish | ||
| dependencies { | ||
| implementation 'ch.qos.logback:logback-classic:1.2.3' | ||
| } | ||
| """.stripIndent(true)) | ||
|
|
||
| addSubproject('bar', """ | ||
| $publish | ||
| dependencies { | ||
| implementation 'junit:junit:4.10' | ||
| } | ||
| """.stripIndent(true)) | ||
|
|
||
| if (GradleVersion.version(gradleVersionNumber) < GradleVersion.version("6.0")) { | ||
| settingsFile << """ | ||
| enableFeaturePreview('GRADLE_METADATA') | ||
| """.stripIndent(true) | ||
| } | ||
|
Comment on lines
+1107
to
+1111
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is never going to be true, minimum version is gradle 7.6.4
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah, this was a copy pasted test There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should i remove all checks for 6.0? |
||
|
|
||
| runTasks('--write-locks') | ||
|
|
||
| when: | ||
| runTasks('generatePomFileForMavenPublication', 'generateMetadataFileForMavenPublication') | ||
|
|
||
| def junitDep = new MetadataFile.Dependency( | ||
| group: 'junit', | ||
| module: 'junit', | ||
| version: [requires: '4.10']) | ||
| def logbackDep = new MetadataFile.Dependency( | ||
| group: 'ch.qos.logback', | ||
| module: 'logback-classic', | ||
| version: [requires: '1.2.3']) | ||
| def slf4jDep = new MetadataFile.Dependency( | ||
| group: 'org.slf4j', | ||
| module: 'slf4j-api', | ||
| version: [requires: '1.7.25']) | ||
|
|
||
| then: "foo's metadata file has the right dependency constraints" | ||
| def fooMetadataFilename = new File(projectDir, "foo/build/publications/maven/module.json") | ||
| def fooMetadata = new ObjectMapper().readValue(fooMetadataFilename, MetadataFile) | ||
|
|
||
| fooMetadata.variants == [ | ||
| new MetadataFile.Variant( | ||
| name: 'runtimeElements', | ||
| dependencies: [logbackDep], | ||
| dependencyConstraints: [logbackDep, slf4jDep]), | ||
| new MetadataFile.Variant( | ||
| name: 'apiElements', | ||
| dependencies: null, | ||
| dependencyConstraints: [logbackDep, slf4jDep]) | ||
| ] as Set | ||
|
|
||
| and: "bar's metadata file has the right dependency constraints" | ||
| def barMetadataFilename = new File(projectDir, "bar/build/publications/maven/module.json") | ||
| def barMetadata = new ObjectMapper().readValue(barMetadataFilename, MetadataFile) | ||
|
|
||
| barMetadata.variants == [ | ||
| new MetadataFile.Variant( | ||
| name: 'runtimeElements', | ||
| dependencies: [junitDep], | ||
| dependencyConstraints: [junitDep]), | ||
| new MetadataFile.Variant( | ||
| name: 'apiElements', | ||
| dependencies: null, | ||
| dependencyConstraints: [junitDep]), | ||
| ] as Set | ||
|
|
||
| where: | ||
| gradleVersionNumber << GRADLE_VERSIONS | ||
| } | ||
|
|
||
| def "#gradleVersionNumber: published constraints are derived from lock file (without local constraints and without filtering)"() { | ||
| setup: | ||
| gradleVersion = gradleVersionNumber | ||
|
|
||
|
|
||
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?
Uh oh!
There was an error while loading. Please reload this page.
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.
Yep sounds good to me, as the deps dumped into
<dependencyManagement>is noise anyways, so not publishing any dep constraints to GMM is equivalent to the status quo. Looking for a second opinion before I commit this though (as this is not my PR)