From 25c9503008ff0c29b5572b05f1e1a8d0770068d7 Mon Sep 17 00:00:00 2001 From: Martin Chalupa Date: Wed, 3 Nov 2021 16:46:52 -0700 Subject: [PATCH] Fix merging configuration with the same changes --- .../diff/PathAwareDiffReportGenerator.kt | 5 ++- .../PathAwareDependencyDiffSpec.groovy | 43 +++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/nebula/plugin/dependencylock/diff/PathAwareDiffReportGenerator.kt b/src/main/kotlin/nebula/plugin/dependencylock/diff/PathAwareDiffReportGenerator.kt index 6e249f5..88967dc 100644 --- a/src/main/kotlin/nebula/plugin/dependencylock/diff/PathAwareDiffReportGenerator.kt +++ b/src/main/kotlin/nebula/plugin/dependencylock/diff/PathAwareDiffReportGenerator.kt @@ -214,12 +214,15 @@ class PathAwareDiffReportGenerator : DiffReportGenerator { other as DependencyPathElement if (selected.id != other.selected.id) return false + if (children != other.children) return false return true } override fun hashCode(): Int { - return selected.id.hashCode() + var result = selected.id.hashCode() + result = 31 * result + children.hashCode() + return result } } diff --git a/src/test/groovy/nebula/plugin/dependencylock/PathAwareDependencyDiffSpec.groovy b/src/test/groovy/nebula/plugin/dependencylock/PathAwareDependencyDiffSpec.groovy index fc386cc..e507340 100644 --- a/src/test/groovy/nebula/plugin/dependencylock/PathAwareDependencyDiffSpec.groovy +++ b/src/test/groovy/nebula/plugin/dependencylock/PathAwareDependencyDiffSpec.groovy @@ -64,6 +64,10 @@ class PathAwareDependencyDiffSpec extends IntegrationTestKitSpec { 'test.example:transitive-consumer4:2.0.0 -> test.example:transitive-dependency:2.0.0', 'some.group:dependency:1.0.0', 'some.group:dependency:2.0.0', + 'test.example:dependency1:1.0.0', + 'test.example:dependency1:2.0.0', + 'test.example:dependency2:1.0.0', + 'test.example:dependency2:2.0.0', ] def generator = new GradleDependencyGenerator(new DependencyGraph(myGraph)) @@ -859,4 +863,43 @@ class PathAwareDependencyDiffSpec extends IntegrationTestKitSpec { common.change.description == "new local submodule" common.change.type == "NEW" } + + def 'properly aggregate configurations with the same dependencies into report'() { + new File("${projectDir}/gradle.properties").text = "systemProp.nebula.features.pathAwareDependencyDiff=true" + def dependenciesLock = new File(projectDir, 'dependencies.lock') + buildFile << """\ + plugins { + id 'nebula.dependency-lock' + } + + apply plugin: 'java' + repositories { + maven { url '${repoDir.absolutePath}' } + } + + dependencyLock { + includeTransitives = true + } + + dependencies { + compileOnly 'test.example:dependency1:2.0.0' + runtimeOnly 'test.example:dependency2:2.0.0' + } + """.stripIndent() + + when: + def result = runTasks('generateLock', 'diffLock') + + then: + def lockdiff = new JsonSlurper().parse(new File(projectDir, 'build/dependency-lock/lockdiff.json')) + def directDependenciesCompileClasspath = lockdiff.find { it.configurations.contains("compileClasspath")} ["differentPaths"] + def direct1 = directDependenciesCompileClasspath.find { it.dependency == "test.example:dependency1"} + direct1.version == "2.0.0" + direct1.change.type == "NEW" + + def directDependenciesRuntimeClasspath = lockdiff.find { it.configurations.contains("runtimeClasspath")} ["differentPaths"] + def direct2 = directDependenciesRuntimeClasspath.find { it.dependency == "test.example:dependency2"} + direct2.version == "2.0.0" + direct2.change.type == "NEW" + } }