Skip to content
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

Extend Gradle integration test to catch differences in dependencies #19

Merged
Merged
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
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())
}