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

[RFC] Implemented JAR minimization #273

Closed
wants to merge 1 commit into from

Conversation

superbobry
Copy link

This commit adds two new configuration options to the 'shadowJar' task.
When 'minimizeJar' is set the shadow JAR would only include the classes
for the project the task operates on and its dependencies. The user can
protect other classes from minimization by specifying them as entry
points.

Here's an example configuration

shadowJar {
    minimizeJar = true
    entryPoint 'foo.Foo'
    entryPoint 'foo.Bar'
}

N.B. imported but unused classes are not considered as dependencies.

Closes #198

This commit adds two new configuration options to the 'shadowJar' task.
When 'minimizeJar' is set the shadow JAR would only include the classes
for the project the task operates on and its dependencies. The user can
protect other classes from minimization by specifying them as entry
points.

Here's an example configuration

    shadowJar {
        minimizeJar = true
        entryPoint 'foo.Foo'
        entryPoint 'foo.Bar'
    }

N.B. imported but unused classes are not considered as dependencies.
@ghost
Copy link

ghost commented Mar 2, 2017

@johnrengelman Would love to see this included. Maybe you could take a quick look, as you've been somehow absent to this repository

@superbobry is there a way you could hand me over a version of your shadow plugin in the meantime? Have an urgent need for it ...

@superbobry
Copy link
Author

@TheRealHypo I should point out that the patch is very experimental. I've only tested it on simple examples so far, nothing real. I don't have an artifact at hand right now, but you can easily build one by checking out the PR branch and doing ./gradlew assemble.

@ghost
Copy link

ghost commented Mar 13, 2017

Hey I added a Review comment on one of your files.

Also I needed to include org.apache.ant and org.vager.jDependency to build script class path.

@superbobry
Copy link
Author

I think you need to publish the review to make the comment visible.

for (entryPoint in entryPoints) {
Clazz clazz = cp.getClazz(entryPoint)
if (clazz == null) {
throw new RuntimeException("Entry point not found: " + className);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got an "Property not found Exception "className" on this line.

@ghost
Copy link

ghost commented Mar 13, 2017

I tried to fix it on my own, check if the list is null etc, but after getting everything to work. The created Jar file wasn't executable, i got an error, that doesn't give me a real clue on what is missing now.

But, it shrieked by 50 % that's perfect 😅

Exception in thread "main" java.lang.ExceptionInInitializerError at org.codehaus.groovy.runtime.InvokerHelper.<clinit>(InvokerHelper.java:65) at org.codehaus.groovy.runtime.callsite.CallSiteArray.createCallConstructorSite(CallSiteArray.java:87) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:60) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:235) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:239) at PeekCloppLinkExtract.main(PeekCloppLinkExtract.groovy:16) Caused by: java.lang.NullPointerException at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.<init>(MetaClassRegistryImpl.java:102) at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.<init>(MetaClassRegistryImpl.java:74) at groovy.lang.GroovySystem.<clinit>(GroovySystem.java:36) ... 6 more

Because the Class "PeekCloppLinkExtract" is there, and also properly set in the Manifest.MF

@ghost
Copy link

ghost commented Mar 21, 2017

So I now know that all minimizing Jar Stuff won't work with groovy dependencies. Don't know why ...

@johnrengelman
Copy link
Collaborator

Probably are going to need a way to specify packages that should be force included. My guess is that there's a layer of indirection happening in Groovy that the dependency library can't follow.

@trustin
Copy link

trustin commented Mar 27, 2017

Just an idea - how about using ProGuard for minimization? We (Armeria project) do this when building a shaded JAR - https://github.com/line/armeria/blob/0db6ccb1a3f2c281025e031ca219ac222a849eb3/core/build.gradle#L33

@superbobry
Copy link
Author

Probably are going to need a way to specify packages that should be force included. My guess is that there's a layer of indirection happening in Groovy that the dependency library can't follow.

Do you know if maven-shade-plugin is able to minimize a JAR with Groovy code correctly?

@Fjolnir-Dvorak
Copy link

Is this still active and/or should I help with this?

@superbobry
Copy link
Author

@Fjolnir-Dvorak I haven't looked into this for a while, feel free to take it over if you want.

@skmedix
Copy link

skmedix commented Oct 16, 2017

Any progress about this? It's a really needed feature for projects with many dependencies.

@johnrengelman
Copy link
Collaborator

This is now implemented in the latest release.

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

Successfully merging this pull request may close these issues.

5 participants