Skip to content

Commit 6a38c36

Browse files
committed
Extend Gradle integration test to catch differences in dependencies
It now fails if the dependencies in Gradle Metadata differ from the dependencies in the corresponding POM. See: FasterXML/jackson-core#999
1 parent fc4692b commit 6a38c36

File tree

1 file changed

+34
-6
lines changed

1 file changed

+34
-6
lines changed

src/test/resources/com/fasterxml/jackson/integtest/gradle/build.gradle.kts

+34-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ plugins {
33
}
44

55
val modulesWithoutGradleMetadata = listOf(
6-
"com.fasterxml.jackson.module:jackson-module-afterburner", // TODO remove after next release - fixed in https://github.com/FasterXML/jackson-modules-base/pull/198
76
"com.fasterxml.jackson.jr:jackson-jr-all", // TODO is there a reason not to add this?
87

98
"com.fasterxml.jackson:jackson-bom", // does not need it
@@ -31,14 +30,14 @@ dependencies.components.withModule("com.fasterxml.jackson:jackson-bom") {
3130

3231
tasks.register("checkMetadata") {
3332
doLast {
33+
var message = ""
34+
3435
configurations.compileClasspath.get().resolve() // triggers the rule above
3536

3637
// Create dependencies to all Modules references in the BOM
3738
val allModules = configurations.detachedConfiguration(*allJacksonModule.map { dependencies.create(it) }.toTypedArray())
3839
// Tell Gradle to do the dependency resolution and return the result with dependency information
39-
val allModulesResolved = allModules.incoming.resolutionResult.allComponents.filter {
40-
it.moduleVersion!!.group.startsWith("com.fasterxml.jackson") && !modulesWithoutGradleMetadata.contains(it.moduleVersion!!.module.toString())
41-
}
40+
val allModulesResolved = resolveJacksonModules(allModules)
4241

4342
val allModulesWithoutBomDependency = mutableListOf<String>()
4443
allModulesResolved.forEach { component ->
@@ -47,8 +46,37 @@ tasks.register("checkMetadata") {
4746
}
4847
}
4948
if (allModulesWithoutBomDependency.isNotEmpty()) {
50-
val message = "Missing dependency to 'jackson-bom'. Gradle Metadata publishing is most likely broken:\n - ${allModulesWithoutBomDependency.joinToString("\n - ")}"
49+
message += "Missing dependency to 'jackson-bom'. Gradle Metadata publishing is most likely broken:\n - ${allModulesWithoutBomDependency.joinToString("\n - ")}\n"
50+
}
51+
52+
// fetch again in a separate context using only the POM metadata
53+
repositories.all {
54+
(this as MavenArtifactRepository).metadataSources {
55+
mavenPom()
56+
ignoreGradleMetadataRedirection()
57+
}
58+
}
59+
val pomAllModules = configurations.detachedConfiguration(*allJacksonModule.map { dependencies.create(it) }.toTypedArray())
60+
val pomAllModulesResolved = resolveJacksonModules(pomAllModules)
61+
allModulesResolved.forEachIndexed { index, gmmModule ->
62+
val pomModule = pomAllModulesResolved[index]
63+
64+
val pomDependencies = pomModule.dependencies.map { it.toString() }
65+
val gmmDependencies = gmmModule.dependencies.filter { !it.requested.displayName.startsWith("com.fasterxml.jackson:jackson-bom:") }.map { it.toString() }
66+
if (pomDependencies != gmmDependencies) {
67+
message += "Dependencies of ${pomModule.id} are wrong in Gradle Metadata:" +
68+
"\n POM: ${pomDependencies.joinToString()}" +
69+
"\n Gradle: ${gmmDependencies.joinToString()}" +
70+
"\n"
71+
}
72+
}
73+
if (message.isNotEmpty()) {
5174
throw RuntimeException(message)
5275
}
5376
}
54-
}
77+
}
78+
79+
fun resolveJacksonModules(allModules: Configuration) =
80+
allModules.incoming.resolutionResult.allComponents.filter {
81+
it.moduleVersion!!.group.startsWith("com.fasterxml.jackson") && !modulesWithoutGradleMetadata.contains(it.moduleVersion!!.module.toString())
82+
}

0 commit comments

Comments
 (0)