I have some JSON resource files in src/main/resources
of the project. And those json files have some comments.
I wanted to strip out the JSON comments before package distribution during the gradle build.
I could strip out comments from src/main/resources
files and package. But I don’t want to strip out comments from src/main/resources
. I just wanted to remove the comments from json files during the gradle build so that only build/resources/main
has json files with no comments.
Below code removes comments from src/main/resource
(which I don’t want, just want json files with no comments in build/resources/main
folder) and I tried with File("build/resources/main/${this.path}")
but does not remove comments.
fileTree(file("src/main/resources/")).visit {
val mapper = com.fasterxml.jackson.databind.ObjectMapper()
mapper.enable(com.fasterxml.jackson.databind.SerializationFeature.INDENT_OUTPUT)
mapper.enable(com.fasterxml.jackson.core.JsonParser.Feature.ALLOW_COMMENTS)
if (this.path.endsWith(".json")) {
val r = mapper.writeValueAsString(mapper.readTree(File("src/main/resources/${this.path}").readText()))
val myfile = File("src/main/resources/${this.path}")
// val myfile = File("build/resources/main/${this.path}") tried but not removing comments
myfile.writeText(r)
}
}
Any help or suggestions would be appreciated!