Skip to content

Commit

Permalink
Fix unnecessary shaded API, shrinks jar from 6 to 2.6 MB. Closes GH-28
Browse files Browse the repository at this point in the history
The Bukkit API was specified with compile scope, causing it to be shaded
into the plugin jar by default. Requested change to Bukkit/SamplePlugin
here: Bukkit/SamplePlugin#16 - to scope
provided, this is intended for dependencies provided at runtime (i.e.,
Bukkit) so removes all the unnecessary deps in the jar, ebean etc.

Remainder of this commit is coping with this fix: cleaning up the
unneeded relocations and exclusions, and breaking the unintentional
dependency on Google Commons where Charset was used although it is not
needed and available in java.nio. Netty is still shaded for server
software version independence, but even with it included and the
NetCraft binary, end result is plugin shrinks from 6.0 to 2.6 MB, well
under the Spigot Resources limit of 4 MB.
  • Loading branch information
satoshinm committed Apr 17, 2017
1 parent ab3809c commit 86e57f5
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 48 deletions.
47 changes: 1 addition & 46 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<artifactId>spigot-api</artifactId>
<version>1.11-R0.1-SNAPSHOT</version>
<type>jar</type>
<scope>compile</scope>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.netty</groupId>
Expand Down Expand Up @@ -87,52 +87,7 @@
io.github.satoshinm.WebSandboxMC.dep.io.netty
</shadedPattern>
</relocation>
<relocation>
<pattern>com.avaje</pattern>
<shadedPattern>
io.github.satoshinm.WebSandboxMC.dep.com.avaje
</shadedPattern>
</relocation>
<relocation>
<pattern>com.google</pattern>
<shadedPattern>
io.github.satoshinm.WebSandboxMC.dep.com.google
</shadedPattern>
</relocation>
<relocation>
<pattern>org.apache</pattern>
<shadedPattern>
io.github.satoshinm.WebSandboxMC.dep.org.apache
</shadedPattern>
</relocation>
<relocation>
<pattern>org.hamcrest</pattern>
<shadedPattern>
io.github.satoshinm.WebSandboxMC.dep.org.hamcrest
</shadedPattern>
</relocation>
<relocation>
<pattern>org.json</pattern>
<shadedPattern>
io.github.satoshinm.WebSandboxMC.dep.org.json
</shadedPattern>
</relocation>
<relocation>
<pattern>org.yaml</pattern>
<shadedPattern>
io.github.satoshinm.WebSandboxMC.dep.org.yaml
</shadedPattern>
</relocation>
</relocations>
<artifactSet>
<excludes>
<excludes>org.spigotmc:*</excludes>
<excludes>net.md_5:*</excludes>
<excludes>javax.persistence:*</excludes>
<excludes>com.avaje:*</excludes>
<excludes>org.hamcrest:*</excludes>
</excludes>
</artifactSet>
</configuration>
</execution>
</executions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package io.github.satoshinm.WebSandboxMC.ws;

import com.google.common.base.Charsets;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelFuture;
Expand Down Expand Up @@ -81,7 +80,7 @@ private void sendTextResource(String prepend, String name, String mimeType, Full
buffer.append(line);
buffer.append('\n');
}
ByteBuf content = Unpooled.copiedBuffer(buffer, Charsets.UTF_8);
ByteBuf content = Unpooled.copiedBuffer(buffer, java.nio.charset.Charset.forName("UTF-8"));

FullHttpResponse res = new DefaultFullHttpResponse(HTTP_1_1, OK, content);

Expand Down

0 comments on commit 86e57f5

Please sign in to comment.