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

Support a full shrinking mode in for UnusedTracker using R8 #565

Closed
netomi opened this issue Apr 15, 2020 · 5 comments
Closed

Support a full shrinking mode in for UnusedTracker using R8 #565

netomi opened this issue Apr 15, 2020 · 5 comments

Comments

@netomi
Copy link
Contributor

netomi commented Apr 15, 2020

This is a suggestion for an improvement to an existing feature of this awesome gradle plugin.

The current minimize feature is relatively simple and is not able to shrink all unused classes from 3rd party libraries. For my own use-case this was not sufficient, having a full shrinking support together with relocation re-use of a lot of classes not available as stand-alone jars / classes would be much easier (that was actually my use-case, I wanted to use single classes from large jars without copying the content).

The shadowJar plugin has already all the features that you need for this purpose, it just lacks support for a full shrinker like ProGuard or R8. ProGuard is unfortunately GPL so I decided to provide a version of the UnusedTracker class that uses R8 for doing the dirty work.

Please take a look at my pull request. I tested it with various projects (even with the R8 project itself) and it works pretty fine. I am open to suggestions and improvements. The current integration was a quick and dirty proof of concept.

I would be happy if the feature request would be accepted.

The pull request currently uses the latest dev version of R8 which is not yet available on the normal google maven repo.

@netomi
Copy link
Contributor Author

netomi commented Apr 17, 2020

I have added a demonstration of this pull request to this branch of my project:

https://github.com/netomi/uom/tree/shadow-dependencies

It pulls 1 class from hibernate-validator and uses 1 method from guava:

  • ConcurrentReferenceHashMap
  • Suppliers.memoize

with the original minimize feature many more classes would be shadowed, like annotation classes for code in guava ....

With the use of R8 this can be greatly reduced, only necessary classes are shadowed which would allow me to use this functionality rather than copying or rewriting the code when you dont want to pull in such a big dependency.

@gildor
Copy link

gildor commented Aug 24, 2020

@netomi Maybe this issue and #566 would be accepted if use a bit different approach: Extract UnusedTrackerWithR8 to own dependency (or better a Gradle plugin, it's more flexible, allows configure custom tasks and provide extensions DSL), contribute to ShadowCopyAction.groovy only parts required to provide custom tracker using shadow plugin public api which allows specifying custom UnusedTracker (it may be as simple as providing a factory for UnusedTracker)

I believe this feature has a great potential, especially if it would be possible to configure r8 with proguard config file.

If all required APIs on ShadowPlugin would be in place and it would be possible to provide custom UnusedTracker it makes it easier to try R8 and do not depend on ShadowPlugin release cycle

@netomi
Copy link
Contributor Author

netomi commented Aug 24, 2020

Your comment makes sense. I am willing to update the PR to take your comments into account. My first version was a proof-of-concept to see if there is general interest in this idea. It should be changed to be able to select different shrinking modes and to select custom configuration as needed for tools like R8 / Proguard.

@StragaSevera
Copy link

@netomi Is there any update on this feature? It would be ultra-cool to have the ability to use minimization from ShadowJar =-)

@netomi
Copy link
Contributor Author

netomi commented Nov 27, 2020

Its a nice feature imho, so far I did not get any feedback from the maintainer of the plugin, but I am willing to update my PR if there is interest to integrate it.

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

3 participants