From 2b8c3386bec9901846de605b0e64b8c8a9146ae6 Mon Sep 17 00:00:00 2001 From: Gabriel Ittner Date: Mon, 25 Sep 2023 15:27:04 +0200 Subject: [PATCH] sort POM dependencies before comparison (#640) --- .../com/vanniktech/maven/publish/Subjects.kt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/plugin/src/integrationTest/kotlin/com/vanniktech/maven/publish/Subjects.kt b/plugin/src/integrationTest/kotlin/com/vanniktech/maven/publish/Subjects.kt index a85f812a..f66a6432 100644 --- a/plugin/src/integrationTest/kotlin/com/vanniktech/maven/publish/Subjects.kt +++ b/plugin/src/integrationTest/kotlin/com/vanniktech/maven/publish/Subjects.kt @@ -20,6 +20,7 @@ import kotlin.io.path.exists import kotlin.io.path.inputStream import kotlin.io.path.name import kotlin.io.path.readText +import org.apache.maven.model.Dependency import org.apache.maven.model.Model import org.apache.maven.model.io.xpp3.MavenXpp3Reader import org.apache.maven.model.io.xpp3.MavenXpp3Writer @@ -265,6 +266,7 @@ class PomSubject private constructor( val pomWriter = MavenXpp3Writer() val actualModel = MavenXpp3Reader().read(artifact.inputStream()) + actualModel.sortDependencies() val actualWriter = StringWriter() pomWriter.write(actualWriter, actualModel) @@ -276,9 +278,21 @@ class PomSubject private constructor( dependencies, dependencyManagementDependencies, ) + expectedModel.sortDependencies() val expectedWriter = StringWriter() pomWriter.write(expectedWriter, expectedModel) assertThat(actualWriter.toString()).isEqualTo(expectedWriter.toString()) } + + private fun Model.sortDependencies() { + dependencies = dependencies.sortedWith(comparator) + if (dependencyManagement != null) { + dependencyManagement.dependencies = dependencyManagement.dependencies.sortedWith(comparator) + } + } + + private val comparator = compareBy { + "${it.scope} ${it.groupId}:${it.artifactId}:${it.version}@${it.classifier}" + } }