diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index ed402458d..46c357d46 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -16,5 +16,6 @@ dependencies { implementation("com.adarshr:gradle-test-logger-plugin:4.0.0") // used by yaml-to-json buildSrc plugin implementation("com.fasterxml.jackson.core:jackson-databind:2.15.3") - implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.15.3") + // use snakeyaml instead of jackson-dataformat-yaml to properly handle yaml anchors and write them as actual values to json + implementation("org.yaml:snakeyaml:2.2") } diff --git a/buildSrc/src/main/kotlin/yaml-to-json.gradle.kts b/buildSrc/src/main/kotlin/yaml-to-json.gradle.kts index 0e7e54cc8..e659fb5d2 100644 --- a/buildSrc/src/main/kotlin/yaml-to-json.gradle.kts +++ b/buildSrc/src/main/kotlin/yaml-to-json.gradle.kts @@ -1,6 +1,5 @@ import com.fasterxml.jackson.databind.ObjectMapper -import com.fasterxml.jackson.dataformat.yaml.YAMLFactory -import org.gradle.kotlin.dsl.create +import org.yaml.snakeyaml.Yaml interface Yaml2JsonPluginExtension { val input: Property @@ -9,7 +8,13 @@ interface Yaml2JsonPluginExtension { class Yaml2JsonPlugin : Plugin { val jsonMapper = ObjectMapper() - val yamlMapper = ObjectMapper(YAMLFactory()) + // https://github.com/FasterXML/jackson-dataformats-text/issues/98 + /* We use snakeyaml since it can handle Anchors and References (Aliases) in yml files, which jackson can't apparently. + * We still can use jackson to write to json, because at that time, + * the Map we created from yaml will contain proper values and not simply anchor names, + * like it happens when using jackson to read yaml. + */ + val yamlMapper = Yaml() override fun apply(p: Project) { val ext = p.extensions.create("yaml2jsonExt") @@ -50,8 +55,7 @@ class Yaml2JsonPlugin : Plugin { } private fun writeYamlToJson(src: File, dest: File) { - val map = yamlMapper.readValue(src.inputStream(), Map::class.java) + val map = yamlMapper.loadAs(src.inputStream(), Map::class.java) jsonMapper.writeValue(dest, map) } } -