Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven with Proguard and assembly plugin

I am trying to use Maven with the following configuration:

  1. Use maven-assembly-plugin to build a single JAR with all dependencies (assembly:single).
  2. Use Proguard plugin afterwards to prune all unnecessary classes from included libraries.

I need proguard to shrink the size of the dependencies. The OpenIMAJ library I'm using is huge (100MB), and I only need a small subset of it.

The problem is that my current Maven config runs the plugins in opposite order - Proguard runs first and builds a JAR without the dependencies.

Plugin section of my pom.xml:

<plugins>
    <plugin>
        <groupId>com.github.wvengen</groupId>
        <artifactId>proguard-maven-plugin</artifactId>
        <version>2.0.6</version>
        <executions>
            <execution>
                <phase>package</phase>
                <goals><goal>proguard</goal></goals>
            </execution>
        </executions>
        <dependencies>
            <dependency>
                <groupId>net.sf.proguard</groupId>
                <artifactId>proguard-base</artifactId>
                <version>4.9</version>
                <scope>runtime</scope>
            </dependency>
        </dependencies>
        <configuration>
            <proguardVersion>4.9</proguardVersion>
            <options>
                <option>-verbose</option>
                <option>-dontobfuscate</option>
                <option>-dontoptimize</option>
                <option>-keep class org.apache.** { *; }</option>
                <option>-keep class no.** { *; }</option>
            </options>
            <libs>
                <lib>${java.home}/lib/rt.jar</lib>
                <lib>${java.home}/lib/jsse.jar</lib>
            </libs>
        </configuration>

    </plugin>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.0</version>
        <configuration>
            <source>1.7</source>
            <target>1.7</target>
        </configuration>
    </plugin>

    <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <configuration>
            <archive>
                <manifest>
                    <mainClass>fully.qualified.MainClass</mainClass>
                </manifest>
            </archive>
            <descriptorRefs>
                <descriptorRef>jar-with-dependencies</descriptorRef>
            </descriptorRefs>
        </configuration>
        <executions>
            <execution>
                <id>make-assembly</id> <!-- this is used for inheritance merges -->
                <phase>package</phase> <!-- bind to the packaging phase -->
                <goals>
                    <goal>single</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
</plugins>
like image 720
bjorncs Avatar asked May 30 '13 21:05

bjorncs


1 Answers

Both plugin are configured to be executed on the package phase. Therefore, I think Maven will execute them in the order they are defined in the pom. (Apparently so, since Maven 3.0.3: http://www.mkyong.com/maven/maven-plugin-execution-order-in-same-phase/)

Did you try to define them the order way around?

If it doesn't work, you should probably try to run the assembly plugin during the prepare-package phase.

However, my answer only worth for the ordering, I'm not sure if that will help you with the whole shrinking thing.

like image 164
Aurélien Thieriot Avatar answered Oct 21 '22 07:10

Aurélien Thieriot