IDFC Maven ProGuard Plug-in Wiki
A maven plugin for obfuscating java code via ProGuard
Brought to you by:
rsand2
This example shows the pom.xml for a web application archive. The obfuscator takes in the class files and some of the dependencies and obfuscates them together, and outputs a single jar file into the WEB/lib folder. The obfuscated jar file, as well as the obfuscation mapping, are attached to the project as artifacts. Note how the single outputArtifact element just specifies the alternative output file name and type for the created artifact (creating a jar not a war, and creating it into the WEB-INF/lib).
<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>com.idfconnect.sample</groupId> <artifactId>sampleweb</artifactId> <packaging>war</packaging> <version>1.0.1</version> <name>IDFConnect Sample Webapp</name> <url>http://www.idfconnect.com</url> <dependencies> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency> <dependency> <!-- this sample we will include in our obfuscation as an -injars parameter --> <groupId>com.idfconnect.sample</groupId> <artifactId>sampleinclusion</artifactId> </dependency> <dependency> <!-- this sample will automatically become a -libraryjars parameter --> <groupId>com.idfconnect.sample</groupId> <artifactId>sampledependency</artifactId> </dependency> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.5</version> </dependency> </dependencies> </dependencyManagement> <build> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.6</source> <target>1.6</target> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.4</version> <configuration> </configuration> </plugin> <!-- BEGIN OBFUSCATE --> <plugin> <groupId>com.idfconnect.devtools</groupId> <artifactId>idfc-proguard-maven-plugin</artifactId> <version>1.0.0</version> <executions> <execution> <phase>prepare-package</phase> <goals> <goal>obfuscate</goal> </goals> </execution> </executions> <configuration> <options> <repackageclasses>com.idfconnect.sample.obfuscated</repackageclasses> <keepattributes>Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,*Annotation*,Synthetic,EnclosingMethod</keepattributes> </options> <inputFile>${project.build.outputDirectory}</inputFile> <inputFileFilter>**.class</inputFileFilter> <inputArtifacts> <inputArtifact>com.idfconnect.sample:sampleinclusion</inputArtifact> </inputArtifacts> <outputArtifacts> <outputArtifact> <file>${project.build.finalName}/WEB-INF/lib/${project.build.finalName}.jar</file> <type>jar</type> </outputArtifact> </outputArtifacts> <libraryArtifacts> <libraryArtifact>junit:junit:4.11</libraryArtifact> </libraryArtifacts> <libraryJarPaths> <libraryJarPath>${java.home}/lib/jsse.jar</libraryJarPath> </libraryJarPaths> </configuration> <dependencies> <dependency> <groupId>net.sf.proguard</groupId> <artifactId>proguard-base</artifactId> <version>4.9</version> </dependency> </dependencies> </plugin> <!-- END OBFUSCATE --> </plugins> </build> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> </project>