gr8 icon indicating copy to clipboard operation
gr8 copied to clipboard

How can I merge resource files such as service files and MANIFEST?

Open SettingDust opened this issue 2 years ago • 5 comments

SettingDust avatar Oct 22 '23 05:10 SettingDust

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?

martinbonnin avatar Nov 25 '24 16:11 martinbonnin

For MANIFEST, I'm not sure, what do you want to merge?

The attributes in MANIFEST.MF

SettingDust avatar Nov 26 '24 01:11 SettingDust

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?

martinbonnin avatar Nov 26 '24 08:11 martinbonnin

图片 图片

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

SettingDust avatar Nov 26 '24 09:11 SettingDust

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") } }
        )
      }
    }

martinbonnin avatar Nov 26 '24 09:11 martinbonnin

I'm going to close this one. This can be done outside Gr8.

martinbonnin avatar Aug 30 '25 11:08 martinbonnin