How can I merge resource files such as service files and MANIFEST?
Woops sorry I managed to miss that issue completely.
~~For services, I would expect R8 to do it automatically. Just make sure to keep your services interfaces.~~
Edit: it won't merge if several implementations implement the same interface.
For MANIFEST, I'm not sure, what do you want to merge?
For MANIFEST, I'm not sure, what do you want to merge?
The attributes in MANIFEST.MF
I don't think R8 has support for that. You could file a feature request at https://issuetracker.google.com/u/1/issues/new?component=192708&template=840533 but my hunch is that such a feature would require some logic: if 2 attributes conflict, what should be the result? I'm not sure that belongs in R8 or Gr8. You could do a post-processing task for an example to replace the Manifest in the minified jar.
Out of curiosity, what's the use case? What attributes do you need merged?
Mainly the MixinConfigs. It's a comma split list of files.
Custom transformer/merge is required
The workaround I'm using in shadow https://github.com/GradleUp/shadow/issues/278#issuecomment-1666511391
I see, thanks for providing this.
Shadow supports Transformers for resources and, because it's a Jar task, it also supports merging manifest using Manifest.from() (source)
Doing the same without writing a 2nd jar in Gr8 would require R8 to accept a callback to modify the jar content on the fly, which is currently not possible.
You can still achieve the same though with a custom task that takes the shadowed jar and rewrites the manifest. Something like so (wildly untested):
val shadowedJar = create("default") {
// ...
}
val rewriteManifest = tasks.register("rewriteManifest", Jar::class.java) {
from(shadowedJar)
manifest {
from(
configurations
.flatMap { it.files }
.map { zipTree(it) }
.map { zip -> zip.find { it.name.equals("MANIFEST.MF") } }
)
}
}
I'm going to close this one. This can be done outside Gr8.