Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
SettingDust opened this issue Oct 22, 2023 · 5 comments
Open

Comments

@SettingDust
Copy link

No description provided.

@martinbonnin
Copy link
Member

martinbonnin commented Nov 25, 2024

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?

@SettingDust
Copy link
Author

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

The attributes in MANIFEST.MF

@martinbonnin
Copy link
Member

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?

@SettingDust
Copy link
Author

SettingDust commented Nov 26, 2024

图片
图片

Mainly the MixinConfigs. It's a comma split list of files.

Custom transformer/merge is required

The workaround I'm using in shadow GradleUp/shadow#278 (comment)

@martinbonnin
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants