Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
reduce size of jar with shade and proguard
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>x</groupId>
<artifactId>y</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>y</name>
<dependencies>
<dependency>
<groupId>com.goebl</groupId>
<artifactId>david-webb</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20140107</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.10</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/maven/</exclude>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
<minimizeJar>true</minimizeJar>
<shadedArtifactAttached>true</shadedArtifactAttached>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>${mainClass}</Main-Class>
</manifestEntries>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.ApacheLicenseResourceTransformer"></transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.ApacheNoticeResourceTransformer">
<addHeader>false</addHeader>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.DontIncludeResourceTransformer">
<resource>.txt</resource>
</transformer>
</transformers>
<relocations>
<relocation>
<pattern>com</pattern>
<shadedPattern>hidden.com</shadedPattern>
</relocation>
<relocation>
<pattern>org</pattern>
<shadedPattern>hidden.org</shadedPattern>
</relocation>
</relocations>
</configuration>
</plugin>
<!-- <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<mainClass>${mainClass}</mainClass>
</manifest>
</archive>
</configuration>
</plugin>-->
<plugin>
<groupId>com.github.wvengen</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<version>2.0.9</version>
<executions>
<!-- <execution>
<id>small</id>
<phase>package</phase>
<goals>
<goal>proguard</goal>
</goals>
<configuration>
<proguardVersion>5.2</proguardVersion>
<attach>true</attach>
<options>
<option>-optimizationpasses 5</option>
<option>-overloadaggressively</option>
<option>-allowaccessmodification</option>
<option>-repackageclasses 'hidden'</option>
<option>-keep public class ${mainClass} { public static void main(java.lang.String[]); }</option>
</options>
<assembly>
<inclusions>
<inclusion>
<groupId>com.goebl</groupId>
<artifactId>david-webb</artifactId>
</inclusion>
<inclusion>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
</inclusion>
<inclusion>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<filter>!**/*.txt</filter>
</inclusion>
</inclusions>
</assembly>
<libs>
<lib>${java.home}/lib/rt.jar</lib>
<lib>${java.home}/lib/jce.jar</lib>
</libs>
</configuration>
</execution>-->
<execution>
<id>shaded-small</id>
<phase>package</phase>
<goals>
<goal>proguard</goal>
</goals>
<configuration>
<proguardVersion>5.2</proguardVersion>
<attach>true</attach>
<options>
<option>-optimizationpasses 5</option>
<option>-overloadaggressively</option>
<option>-allowaccessmodification</option>
<option>-repackageclasses 'hidden'</option>
<option>-keep public class ${mainClass} { public static void main(java.lang.String[]); }</option>
</options>
<injar>${project.build.finalName}-shaded.jar</injar>
<includeDependency>false</includeDependency>
<libs>
<lib>${java.home}/lib/rt.jar</lib>
<lib>${java.home}/lib/jce.jar</lib>
</libs>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<maven.compiler.debug>true</maven.compiler.debug>
<maven.compiler.debuglevel>lines,vars,source</maven.compiler.debuglevel>
<maven.compiler.showDeprecation>true</maven.compiler.showDeprecation>
<maven.compiler.showWarnings>true</maven.compiler.showWarnings>
<argLine>-Dfile.encoding=${project.build.sourceEncoding}</argLine>
<failOnMissingWebXml>false</failOnMissingWebXml>
<mainClass>x.Main</mainClass>
</properties>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.