-
Notifications
You must be signed in to change notification settings - Fork 393
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
JAR minimization #198
Comments
If someone would like to provide a PR, sure. |
FYI, android gradle plugin does integrate with proguard, I guess it's possible to look how they did it. |
@johnrengelman Is there any estimated timeline for this? I'm working on a project that's running into jar size issues and it would be ideal if we could use shadow to deal with them. |
No timeline on my side. Again if the community wants to take a crack at it that would be great. |
I am the original author of the minimize functionality. It should really not be that hard to add. |
This would be such a nice future I'm willing to implement it myself, I'll give it a shot @tcurdt could you post a step by step list of what the minimizeJar should do so I dont miss any optimizations, my intial idea is to recursively check class imports through reflection and exclude/include them on the shadowJar task. meanwhile we can use proguard as a gradle task that depends on shadowJar |
@josevimlet Sure, happy to help. Reflection is not the way to go though. The way it works is to build a dependency tree of all classes through byte code introspection. With that available you can find the sum of all transitive class dependencies - which you want to keep. The rest you can safely remove.
The maven plugin code is pretty readable, too. |
Great I've been testing out proguard and I managed to make it work under gradle but I've realised you have to keep adding project specific stuff in its config to make things work, because its shrinking algorithm fails by default on advanced stuff, annotations etc if you don't add the proper config. Therefore I'm afraid its going to be though to implement a general purpose minification, still I'll give it a try and will report any progress here. Thanks a lot @tcurdt <3 |
This was added 4.0.0 |
I see this task closed and build in way to minimize is great, but some comment here and in #225 also mention Proguard and maybe we should reopen it. Because Proguard provides much more advanced minimization, configs. Just, for example, I have a small project, shadowed version of it about 2.2 Mb, minimized shadowed 1.1 Mb, but simple config of Proguard with minimization and obfuscation is only 300 Kb So I believe it's still worth to reopen issue request with Proguard integration |
@gildor be aware that for some people the proguard license is a problem. |
Sure, I understand this, |
I found it a very nice use-case to use a full blown shrinker like ProGuard for the minimize feature. Due to the license problem as ProGuard is GPL software, I decided to use R8 which has similar capabilities wrt shrinking as ProGuard. I opened a new ticket: #565 and added a pull request for a proof of concept implementation. Feedback is welcome! |
There's no problem with ProGuard license.
ProGuard itself is licensed under restrictive GNU GPL v2, and it becomes a problem only if you redistribute it. But you don't, you just add a dependency on it. |
well, linking Apache licensed software with GPL software (as for ProGuard) is not possible, see https://www.apache.org/licenses/GPL-compatibility.html |
Interesting. But
https://www.guardsquare.com/en/products/proguard/manual/license/GPL-exception Android Gradle Plugin have been using ProGuard for decades… |
you should read up on the GPL and its implications before adding a GPL licensed library as dependency. The exception of ProGuard for certain applications does not apply for a gradle plugin imho, see also here: https://github.com/Guardsquare/proguard/blob/master/core/src/proguard/GPL.java only if gradle itself would use ProGuard code directly it would be allowed, any other code using it would violate the GPL and I am sure the FSF would be keen to investigate. |
Woule make sense to open a new issue about supporting proguard specifically, with the links for the licensing info that show it's possible without violating proguard's license. |
Agreed. Let’s not keep this thread going.
|
I am not sure how the discussion diverted to the licensing issue. To avoid any licensing discussions I added a PR #566 to use R8 which is licensed under Apache but having the same capabilities as ProGuard wrt shrinking. |
Yup that’s fine and that PR will be given its own attention. |
Maven's shade plugin has the option to minimize the generated JAR, which is superb for behemoths like Guava. Is this feature a possibility?
The text was updated successfully, but these errors were encountered: