Skip to content

Commit 9fbd211

Browse files
Switch from org.jsom to jackson to preserve property ordering
Gradle wants `formatVersion` to come first, so switch to a json parser does the right thing
1 parent b9a022f commit 9fbd211

File tree

3 files changed

+31
-23
lines changed

3 files changed

+31
-23
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ buildscript {
1414

1515
dependencies {
1616
classpath(libs.dokkaGradlePlugin)
17-
classpath(libs.json)
17+
classpath(libs.jacksonDatabind)
1818
classpath(libs.junitGradlePlugin)
1919
classpath(libs.kotlinGradlePlugin)
2020
classpath(libs.mavenPublishGradlePlugin)

gradle/libs.versions.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ jacksonDatatypeJsr310 = { module = "com.fasterxml.jackson.datatype:jackson-datat
2727
jettyAlpnClient = { module = "org.eclipse.jetty:jetty-alpn-client", version.ref = "jetty" } # for DynamoDBLocal
2828
jettyClient = { module = "org.eclipse.jetty:jetty-client", version.ref = "jetty" } # for DynamoDBLocal
2929
jettyServer = { module = "org.eclipse.jetty:jetty-server", version.ref = "jetty" } # for DynamoDBLocal
30-
json = { module = "org.json:json", version = "20250107" }
3130
junit4Api = { module = "junit:junit", version = "4.13.2" }
3231
junitApi = { module = "org.junit.jupiter:junit-jupiter-api", version = "5.8.2" }
3332
junitEngine = { module = "org.junit.jupiter:junit-jupiter-engine", version = "5.11.4" }

tempest-dynamodb-local/build.gradle.kts

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
import com.fasterxml.jackson.databind.MapperFeature
2+
import com.fasterxml.jackson.databind.SerializationFeature
3+
import com.fasterxml.jackson.databind.json.JsonMapper
4+
import com.fasterxml.jackson.databind.node.ArrayNode
5+
import com.fasterxml.jackson.databind.node.JsonNodeFactory
6+
import com.fasterxml.jackson.databind.node.ObjectNode
17
import com.vanniktech.maven.publish.JavadocJar.Dokka
28
import com.vanniktech.maven.publish.KotlinJvm
39
import com.vanniktech.maven.publish.MavenPublishBaseExtension
4-
import org.json.JSONObject
510

611
plugins {
712
kotlin("jvm")
@@ -85,26 +90,30 @@ tasks.withType<GenerateModuleMetadata>().configureEach {
8590
doLast {
8691
try {
8792
outputFile.get().asFile.takeIf { it.exists() }?.let { moduleFile ->
88-
val moduleJson = JSONObject(moduleFile.readText())
89-
val variants = moduleJson.getJSONArray("variants")
90-
91-
val shadowVariant = (0 until variants.length())
92-
.map { variants.getJSONObject(it) }
93-
.find { it.getString("name") == "shadowRuntimeElements" }
94-
if (shadowVariant == null) {
95-
throw NoSuchElementException("could not find the `shadowRuntimeElements` variant!")
96-
}
97-
98-
val runtimeVariant = (0 until variants.length())
99-
.map { variants.getJSONObject(it) }
100-
.find { it.getString("name") == "runtimeElements" }
101-
if (runtimeVariant == null) {
102-
throw NoSuchElementException("could not find the `runtimeElements` variant!")
103-
}
104-
105-
runtimeVariant.put("dependencies", shadowVariant.get("dependencies"))
106-
107-
moduleFile.writeText(moduleJson.toString(2))
93+
val mapper = JsonMapper.builder()
94+
.enable(SerializationFeature.INDENT_OUTPUT)
95+
.nodeFactory(JsonNodeFactory.withExactBigDecimals(true))
96+
.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, false)
97+
.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, false)
98+
.build()
99+
val moduleJson = mapper.readTree(moduleFile) as ObjectNode
100+
val variants = moduleJson.get("variants") as ArrayNode
101+
102+
val shadowVariant = variants
103+
.elements().asSequence()
104+
.map { it as ObjectNode }
105+
.find { it.get("name").asText() == "shadowRuntimeElements" }
106+
?: throw NoSuchElementException("could not find the `shadowRuntimeElements` variant!")
107+
108+
val runtimeVariant = variants
109+
.elements().asSequence()
110+
.map { it as ObjectNode }
111+
.find { it.get("name").asText() == "runtimeElements" }
112+
?: throw NoSuchElementException("could not find the `runtimeElements` variant!")
113+
114+
runtimeVariant.replace("dependencies", shadowVariant.get("dependencies"))
115+
116+
moduleFile.writeText(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(moduleJson))
108117
}
109118
} catch (e: Exception) {
110119
throw GradleException("could not post-process the module metadata!", e)

0 commit comments

Comments
 (0)