title: duplicate class definitions while obfuscating Appium based jar using Proguard
body: <p>I'm building a <strong>java</strong> application which uses <code>Appium</code> to automate a mobile app. I'm using <code>Gradle</code> to manage the dependencies. </p>
  
  <p>The project compiles and builds the jar successfully but while obfuscating using <code>gradle proguardtask</code>, following errors are observed.</p>
  
  <pre><code>&gt; Task :proguardTask
  Note: there were 57 duplicate class definitions.
  ...
  ...
  * Exception is:
  org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':proguardTask'.
  ...
  ...
  ...
  Caused by: org.gradle.api.UncheckedIOException: java.io.IOException: 
  Can't write [/home/mmt/eclipse-workspace/MobileTest/build/libs/MobileTest-0.1-obfus.jar] 
  (Can't read [/home/mmt/eclipse-workspace/MobileTest/build/libs/MobileTest-0.1.jar] 
  (Duplicate jar entry [org/openqa/selenium/SearchContext.class]))
  </code></pre>
  
  <p>I tried <code>exclude</code>ing the dependencies which are transitive with no luck. </p>
  
  <p>Tried doing <code>transitive = false</code> and adding the transitive one manually still couldn't get the desired output.</p>
  
  <p>Following is my build script.</p>
  
  <p><strong>build.gradle</strong></p>
  
  <pre><code>
      buildscript {
      repositories {
          mavenLocal()
          mavenCentral()
      }
      dependencies {
          classpath 'net.sf.proguard:proguard-gradle:6.1.1'
      }
      } plugins {
          id 'java'
          id 'maven-publish'
      }
      repositories {
          mavenLocal()
          maven {
              url = 'http://repo.maven.apache.org/maven2'
          }
      }
      dependencies {
          compile 'org.testng:testng:6.14.3'
          compile 'io.appium:java-client:6.1.0'
          compile 'org.apache.poi:poi:3.16'
          compile 'net.sourceforge.tess4j:tess4j:4.3.0'
          compile 'log4j:log4j:1.2.17'
          testCompile 'junit:junit:4.11'
      }
  
      group = 'com.mobile'
      version = '0.1'
      description = 'AppiumTest'
      sourceCompatibility = '1.8'
  
      publishing {
          publications {
              maven(MavenPublication) {
                  from(components.java)
              }
          }
      }
  
      jar{
          from { configurations.compile.collect { zipTree(it) } }
          manifest {
              attributes 'Implementation-Title': 'Jar File with dependencies',  
                  'Implementation-Version': version,
                  'Main-Class': 'com.mobile.MobileTest.App'
          }
      }
  
      task proguardTask(type: proguard.gradle.ProGuardTask,dependsOn: jar) {
          configuration file('proguard.pro')
          injars 'build/libs/MobileTest-0.1.jar'
          outjars 'build/libs/MobileTest-0.1-obfus.jar'   
      }
  
      tasks.withType(JavaCompile) {
          options.encoding = 'UTF-8'
      }
  
      test {
          useTestNG()
      }
  </code></pre>
  
  <p><strong>proguard.pro</strong></p>
  
  <pre><code>-dontoptimize
  -allowaccessmodification
  -dontshrink
  -dontwarn
  -dontpreverify
  -keepattributes Signature
  -keepattributes Exceptions
  -keep public class com.mobile.MobileTest.App {*;}
  -keep class module-info{*;}
  
  -keep public class com.beust.testng.**{*;}
  -keep public interface com.beust.testng.**{*;}
  -keep public enum com.beust.testng.**{*;}
  
  -keep public class org.apache.log4j.**{*;}
  -keep public interface org.apache.log4j.**{*;}
  -keep public enum org.apache.log4j.**{*;}
  
  -keep public class io.appium.java_client.**{*;}
  -keep public interface io.appium.java_client.**{*;}
  -keep public enum io.appium.java_client.**{*;}
  
  -keep public class kobaltBuild.classes.**{*;}
  -keep public interface kobaltBuild.classes.**{*;}
  -keep public enum kobaltBuild.classes.**{*;}
  
  -keep public class net.sourceforge.tess4j.**{*;}
  -keep public interface net.sourceforge.tess4j.**{*;}
  -keep public enum net.sourceforge.tess4j.**{*;}
  
  -keep public class org.**{*;}
  -keep public interface org.**{*;}
  -keep public enum org.**{*;}
  
  -keep public class scripts.**{*;}
  -keep public interface scripts.**{*;}
  -keep public enum scripts.**{*;}
  
  -keep public class src.main.resources.**{*;}
  -keep public interface src.main.resources.**{*;}
  -keep public enum src.main.resources.**{*;}
  
  -keep public class tessdata.**{*;}
  -keep public interface tessdata.**{*;}
  -keep public enum tessdata.**{*;}
  
  -keep public class com.recognition.software.jdeskew.**{*;}
  -keep public interface com.recognition.software.jdeskew.**{*;}
  -keep public enum com.recognition.software.jdeskew.**{*;}
  
  -keep public class bsh.**{*;}
  -keep public interface bsh.**{*;}
  -keep public enum bsh.**{*;}
  
  -keep public class java.**{*;}
  -keep public interface java.**{*;}
  -keep public enum java.**{*;}
  
  -keep public class javax.**{*;}
  -keep public interface javax.**{*;}
  -keep public enum javax.**{*;}
  
  -keep public class org.**{*;}
  -keep public interface org.**{*;}
  -keep public enum org.**{*;}
  </code></pre>
  
  <p>Any pointer in the right direction is much appreciated.</p>
  
  <p><strong>Update</strong></p>
  
  <p>Find the repo <a href="https://github.com/kailashchivhe/MobileTest" rel="nofollow noreferrer">here</a>. </p>