Merge duplicate props files

gradle merge duplicate files

I have this file META-INF\services\org.junit.jupiter.api.extension.Extension in multiple places in source each with respective properties related to that code module

However during the building all these property files needs to be merged and only file with the name org.junit.jupiter.api.extension.Extension should be copied

Is there a merge strategy if no by default, can I extend gradle some way and use it

Sounds like you try to build a bad-practice fat jar.
Such service files are one of the many reasons they are a bad idea.
See for more quotes about it.
If you really want to build such a mess you should probably use John Engelman’s shadow plugin which mitigates some of the problems these fat jars produce, amongst them merging service descriptor files.

Does fatjar help in mergining same file name properties that exist in different locations?

I want to something similar to said above, but looking for a duplicate strategy as Merge, so that, I get all the copy advantages.

How do I create a custom MERGE duplicate strategy

potentially a plugin in like this

I tried using this… but it is not working…

Does fatjar help in mergining same file name properties that exist in different locations?

I assumed you do build a fatjar and because of that have the problem with the same-named files where only one survives.
A fatjar imho does never help for anything but only produce problems.
I would never recommend building a fatjar, except maybe a good-practice one like Spring Boot is doing.

How do I create a custom MERGE duplicate strategy

I don’t think you can. At least I’m not aware of.
Something like that plugin might be what you need then.
If it does not work, I suggest you open a bug report to it.

1 Like

Thank You Vampire, found this workaround (based on some insights from #ChatGPT), it does work in my context,

 register<Copy>("copyMetaInfoTestRes") {
	from(sourceSets.main.get().java.srcDirs) {
	includeEmptyDirs = false
	doLast {


fun Copy.`checkDup&Append`()
    eachFile {
	path = name
	val existingTargetFile = File(destinationDir, name)
	if (existingTargetFile.exists())
	    val duplicatedFileContent = file.readBytes()
	    Files.write(existingTargetFile.toPath(), duplicatedFileContent, StandardOpenOption.APPEND)

Again, do not trust any of the non-sense ChatGPT produces.
I already explained that in other threads, also by you.
Also, do never, ever, ever, ever have tasks with overlapping outputs.
With your task you write into the output directory of the processTestResources task and thus have overlapping outputs.
This causes a lot of problems and performance degradation, so never, ever, ever do that.

1 Like