Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ plugins {
repositories {
mavenCentral()
}

dependencies {
implementation 'org.apache.maven:maven-artifact:3.9.9'
Copy link
Copy Markdown
Author

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

}
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
Expand All @@ -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)
Expand All @@ -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}")
}
}
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The supporting test

}
}
5 changes: 5 additions & 0 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The 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')
}
Expand Down Expand Up @@ -129,6 +130,10 @@ dependencies {
tasks.generatePomFileForMavenJavaPublication.finalizedBy(
tasks.register('checkPOMdependencies', org.testcontainers.build.ComparePOMWithLatestReleasedTask) {
ignore = [
'org.apache.commons:commons-lang3',
]
minimumVersions = [
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The 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',
]
}
)
Expand Down