title: Gradle: How to exclude javax.realtime package from JScience jar dependency (Multiple dex define)
body: <p>I'm using Gradle in my Android application an I would like to use the JScience library dependency. I have added the library this way:</p>
  
  <pre><code>dependencies {
      compile fileTree(dir: 'libs', include: '*.jar')
  
      compile 'org.jscience:jscience:4.3.1'
  
      testCompile group: 'junit', name: 'junit', version: '4.11'
  }
  </code></pre>
  
  <p>But in the compile time I get the error:</p>
  
  <pre><code>UNEXPECTED TOP-LEVEL EXCEPTION:
  com.android.dex.DexException: Multiple dex files define Ljavax/realtime/MemoryArea;
      at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:594)
      at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:552)
      at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:533)
      at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:170)
      at com.android.dx.merge.DexMerger.merge(DexMerger.java:188)
      at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439)
      at com.android.dx.command.dexer.Main.runMonoDex(Main.java:287)
      at com.android.dx.command.dexer.Main.run(Main.java:230)
      at com.android.dx.command.dexer.Main.main(Main.java:199)
      at com.android.dx.command.Main.main(Main.java:103)
  </code></pre>
  
  <p>This is caused because of duplicating <code>javax.realtime</code> packages in project, one is a part of JDK, and the second one is in the Jscience library. I have tried to remove this package from Jscience library this way in Gradle:</p>
  
  <pre><code>sourceSets {
      main {
          java {
              exclude 'javax/realtime/**'
          }
      }
  }
  
  configurations {
      all*.exclude group: 'javax.realtime'
  }
  </code></pre>
  
  <p>But that didn't help. So, that package is still exists in dependencies.
  <img src="https://i.stack.imgur.com/uHEGE.png" alt="enter image description here"></p>
  
  <p>Is there any way how I can exclude a package from jar on compile time?</p>