From 53494f7bcb4e45c9bca8a931d33618e4a6d862e9 Mon Sep 17 00:00:00 2001 From: Robert Stupp Date: Mon, 24 Nov 2025 15:31:23 +0100 Subject: [PATCH] Make pom.xml always reproducible It turned out in practice, that there's no guarantee that the `` element in `pom.xml` files always appear at the same place. This change ensures that the `` elements always appears at a deterministic location at the top of `pom.xml` files. --- .../src/main/kotlin/publishing/configurePom.kt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/build-logic/src/main/kotlin/publishing/configurePom.kt b/build-logic/src/main/kotlin/publishing/configurePom.kt index e8c2c13445..ee57589faf 100644 --- a/build-logic/src/main/kotlin/publishing/configurePom.kt +++ b/build-logic/src/main/kotlin/publishing/configurePom.kt @@ -19,6 +19,7 @@ package publishing +import groovy.namespace.QName import groovy.util.Node import org.gradle.api.Project import org.gradle.api.Task @@ -58,7 +59,23 @@ internal fun configurePom(project: Project, mavenPublication: MavenPublication, val projectNode = asNode() val parentNode = projectNode.appendNode("parent") + // Guarantee that the element is at a deterministic location. + // This is important for reproducible builds! + projectNode.remove(parentNode) + for ((index, any) in projectNode.children().withIndex()) { + if (any is Node) { + val qName = any.name() as QName + if (qName.localPart == "groupId") { + // In theory, we could also replace the groupId element, as the group ID is + // currently the same. + // But this would break once another group ID is built. + projectNode.children().add(index, parentNode) + break + } + } + } val parent = project.parent!! + // Add GAV to element parentNode.appendNode("groupId", parent.group) parentNode.appendNode("artifactId", parent.name) parentNode.appendNode("version", parent.version)