-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Fix dependency conflict after upgrading to Testcontainers 2.0.5 #11776
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: main
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -5,3 +5,7 @@ plugins { | |
| repositories { | ||
| mavenCentral() | ||
| } | ||
|
|
||
| dependencies { | ||
| implementation 'org.apache.maven:maven-artifact:3.9.9' | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| package org.testcontainers.build | ||
|
|
||
| import groovy.xml.XmlSlurper | ||
| import org.apache.maven.artifact.versioning.ComparableVersion | ||
| import org.gradle.api.DefaultTask | ||
| import org.gradle.api.tasks.Input | ||
| import org.gradle.api.tasks.TaskAction | ||
|
|
@@ -10,6 +11,9 @@ class ComparePOMWithLatestReleasedTask extends DefaultTask { | |
| @Input | ||
| Set<String> ignore = [] | ||
|
|
||
| @Input | ||
| Map<String, String> minimumVersions = [:] | ||
|
|
||
| @TaskAction | ||
| def doCompare() { | ||
| def rootNode = new XmlSlurper().parse(project.tasks.generatePomFileForMavenJavaPublication.destination) | ||
|
|
@@ -23,14 +27,28 @@ class ComparePOMWithLatestReleasedTask extends DefaultTask { | |
| def releasedRootNode = new XmlSlurper() | ||
| .parse("https://repo1.maven.org/maven2/org/testcontainers/${artifactId}/${latestRelease}/${artifactId}-${latestRelease}.pom") | ||
|
|
||
| Set<String> dependencies = releasedRootNode.dependencies.children() | ||
| Set<String> releasedDependencies = releasedRootNode.dependencies.children() | ||
| .collect { "${it.groupId.text()}:${it.artifactId.text()}".toString() } | ||
|
|
||
| Map<String, String> currentVersions = [:] | ||
| for (dependency in rootNode.dependencies.children()) { | ||
| def coordinates = "${dependency.groupId.text()}:${dependency.artifactId.text()}".toString() | ||
| if (!dependencies.contains(coordinates) && !ignore.contains(coordinates)) { | ||
| currentVersions[coordinates] = dependency.version.text() | ||
| if (!releasedDependencies.contains(coordinates) && !ignore.contains(coordinates)) { | ||
| throw new IllegalStateException("A new dependency '${coordinates}' has been added to 'org.testcontainers:${artifactId}' - if this was intentional please add it to the ignore list in ${project.buildFile}") | ||
| } | ||
| } | ||
|
|
||
| for (entry in minimumVersions) { | ||
| def coords = entry.key | ||
| def minVersion = entry.value | ||
| def currentVersion = currentVersions[coords] | ||
| if (currentVersion == null || currentVersion.isEmpty()) { | ||
| throw new IllegalStateException("Dependency '${coords}' has a minimum version '${minVersion}' declared in ${project.buildFile} but is missing from the generated POM of 'org.testcontainers:${artifactId}'") | ||
| } | ||
| if (new ComparableVersion(currentVersion) < new ComparableVersion(minVersion)) { | ||
| throw new IllegalStateException("Dependency '${coords}' resolved to '${currentVersion}' in the POM of 'org.testcontainers:${artifactId}', which is below the required minimum '${minVersion}' declared in ${project.buildFile}") | ||
| } | ||
| } | ||
|
Author
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. The supporting test |
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,6 +66,7 @@ dependencies { | |
| compileOnly 'org.jetbrains:annotations:26.1.0' | ||
| testCompileOnly 'org.jetbrains:annotations:26.1.0' | ||
| api 'org.apache.commons:commons-compress:1.28.0' | ||
| api 'org.apache.commons:commons-lang3:3.20.0' | ||
|
Author
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. The main change |
||
| api ('org.rnorth.duct-tape:duct-tape:1.0.8') { | ||
| exclude(group: 'org.jetbrains', module: 'annotations') | ||
| } | ||
|
|
@@ -129,6 +130,10 @@ dependencies { | |
| tasks.generatePomFileForMavenJavaPublication.finalizedBy( | ||
| tasks.register('checkPOMdependencies', org.testcontainers.build.ComparePOMWithLatestReleasedTask) { | ||
| ignore = [ | ||
| 'org.apache.commons:commons-lang3', | ||
| ] | ||
| minimumVersions = [ | ||
|
Author
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. To make the separation and the supporting test clearer |
||
| 'org.apache.commons:commons-lang3': '3.18.0', | ||
| ] | ||
| } | ||
| ) | ||
|
|
||
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.
Is needed to use ComparableVersion to avoid manual parsing.
This should be fine since it's anyway only the build time dependency