Skip to content

Commit

Permalink
Extend Gradle integration test to catch differences in dependencies
Browse files Browse the repository at this point in the history
It now fails if the dependencies in Gradle Metadata differ from the
dependencies in the corresponding POM.

See: FasterXML/jackson-core#999
  • Loading branch information
jjohannes committed Apr 27, 2023
1 parent fc4692b commit 6a38c36
Showing 1 changed file with 34 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ plugins {
}

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

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

tasks.register("checkMetadata") {
doLast {
var message = ""

configurations.compileClasspath.get().resolve() // triggers the rule above

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

val allModulesWithoutBomDependency = mutableListOf<String>()
allModulesResolved.forEach { component ->
Expand All @@ -47,8 +46,37 @@ tasks.register("checkMetadata") {
}
}
if (allModulesWithoutBomDependency.isNotEmpty()) {
val message = "Missing dependency to 'jackson-bom'. Gradle Metadata publishing is most likely broken:\n - ${allModulesWithoutBomDependency.joinToString("\n - ")}"
message += "Missing dependency to 'jackson-bom'. Gradle Metadata publishing is most likely broken:\n - ${allModulesWithoutBomDependency.joinToString("\n - ")}\n"
}

// fetch again in a separate context using only the POM metadata
repositories.all {
(this as MavenArtifactRepository).metadataSources {
mavenPom()
ignoreGradleMetadataRedirection()
}
}
val pomAllModules = configurations.detachedConfiguration(*allJacksonModule.map { dependencies.create(it) }.toTypedArray())
val pomAllModulesResolved = resolveJacksonModules(pomAllModules)
allModulesResolved.forEachIndexed { index, gmmModule ->
val pomModule = pomAllModulesResolved[index]

val pomDependencies = pomModule.dependencies.map { it.toString() }
val gmmDependencies = gmmModule.dependencies.filter { !it.requested.displayName.startsWith("com.fasterxml.jackson:jackson-bom:") }.map { it.toString() }
if (pomDependencies != gmmDependencies) {
message += "Dependencies of ${pomModule.id} are wrong in Gradle Metadata:" +
"\n POM: ${pomDependencies.joinToString()}" +
"\n Gradle: ${gmmDependencies.joinToString()}" +
"\n"
}
}
if (message.isNotEmpty()) {
throw RuntimeException(message)
}
}
}
}

fun resolveJacksonModules(allModules: Configuration) =
allModules.incoming.resolutionResult.allComponents.filter {
it.moduleVersion!!.group.startsWith("com.fasterxml.jackson") && !modulesWithoutGradleMetadata.contains(it.moduleVersion!!.module.toString())
}

0 comments on commit 6a38c36

Please sign in to comment.