title: Android Gradle dependency exclude
body: <p>One another question about <code>dependency</code> duplication/excluding in gradle.
  My problem looks like that:</p>
  
  <p><strong>Dependencies tree:</strong></p>
  
  <ul>
  <li>TesterApp
  
  <ul>
  <li>DataServices
  
  <ul>
  <li>FirstWebService
  
  <ul>
  <li>MyJava.Common.Classes</li>
  </ul></li>
  </ul></li>
  <li>MyAndroidGraphics
  
  <ul>
  <li>MyAndroid.Common.Classes
  
  <ul>
  <li>MyJava.Common.Classes</li>
  </ul></li>
  </ul></li>
  <li>MyUiViews
  
  <ul>
  <li>MyAndroid.Common.Classes
  
  <ul>
  <li>MyJava.Common.Classes</li>
  </ul></li>
  </ul></li>
  </ul></li>
  </ul>
  
  <p><strong>Project Tester App</strong>
  build.gradle</p>
  
  <pre><code>dependencies {
    compile(project(':data.services'))
    compile(project(':my.android.graphics'))
    compile(project(':my.ui.views'))
  }
  </code></pre>
  
  <p><strong>Data.Services</strong> build.gradle</p>
  
  <pre><code>dependencies {
    compile(project(':first.webservice'))
  }
  </code></pre>
  
  <p><strong>My Android Graphics</strong> build.gradle</p>
  
  <pre><code>dependencies {
    compile(project(':my.android.common.classes'))
  }
  </code></pre>
  
  <p><strong>My UI Views</strong> build.gradle</p>
  
  <pre><code>dependencies {
    compile 'me.dm7.barcodescanner:zxing:1.5'
    compile(project(':my.android.common.classes'))
  }
  </code></pre>
  
  <p><strong>My Android Common Classes</strong> build.gradle</p>
  
  <pre><code>dependencies {
    compile 'com.android.support:appcompat-v7:25.2.0'
    compile 'com.android.support:support-v4:25.2.0'
    compile 'com.android.support:cardview-v7:25.2.0'
    compile(project(':my.java.common.classes'))
  }
  </code></pre>
  
  <p><strong>My Java Common Classes</strong> build.gradle</p>
  
  <pre><code>dependencies {
     compile 'com.mcxiaoke.volley:library:1.0.9'
  }
  </code></pre>
  
  <p>As you can see, duplicates are with <code>my.java.common.classes</code> and <code>my.android.common.classes</code>, I cannot merge it as those libraries are used in different projects and are generally common for different projects. </p>
  
  <p>I was trying to use <code>exclude</code> like that</p>
  
  <pre><code>dependencies {
    compile(project(':data.services')){
      exclude module : ':my.java.common.classes'
    }
    compile(project(':my.android.graphics')){
      exclude module : ':my.java.common.classes'
    }
    compile(project(':my.java.common.classes'))
  }
  </code></pre>
  
  <p>Unfortunately doesn't help much, still has </p>
  
  <pre><code>com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK trust_root.bks
  
   File1: D:\projects\android\my.tester.app\my.java.common.classes\build\libs\my.java.common.classes-1.0.jar
   File2: D:\projects\android\my.tester.app\my.android.common.classes\build\libs\my.android.common.classes-1.2.jar
  </code></pre>
  
  <p>Any ideas, please help.</p>