title: Different Gradle dependency for test than for compile
body: <p>I am facing this issue with Android/Gradle dependency system</p>
  
  <ol>
  <li>I have quite a complex JAR library with certain API - say other.jar</li>
  <li>This other.sdk is completely out of my control</li>
  <li>This other.sdk only works on a real phone</li>
  <li>I need to write the jUnit tests to be executed on Jenkins (w/o any real phone attached)</li>
  <li>Therefore I wrote anothe JAR file called say otherMock.jar</li>
  <li>This otherMock.jar has exactly the same API as other.jar</li>
  </ol>
  
  <p>Now I need to do something like this in my build.gradle file:</p>
  
  <pre><code>...
  
  dependencies {
      ...
      testCompile files('libs/otherMock.jar')
      debugCompile files('libs/other.jar')
      releaseCompile files('libs/other.jar')
      ...
  }
  
  ...
  </code></pre>
  
  <p>Unfortunately, Gradle seems then to be including both the other.jar and the otherMock.jar within my test build.</p>
  
  <p>I do understand that for majority of builds (including all my previous) it is perfectly desirable behavior.</p>
  
  <p>But for my particular case it is an issue.</p>
  
  <p>So I would need (for example) something like this:</p>
  
  <pre><code>...
  dependencies {
      if(&lt;I failed to realize which condition to write here to learn it is going to be a test&gt;) {
          testCompile ...
      } else {
          debugCompile ...
          releaseCompile ...
      }
  }
  </code></pre>
  
  <p>Or better:</p>
  
  <pre><code>...
  dependencies {
      testCompile ...
      debugCompile ... {
          exclude &lt;when test build - what to write here?&gt;
      }
  }
  ...
  </code></pre>
  
  <p>I did my best to realize how to configure Gradle to do what I need here, but I failed :(</p>
  
  <p>On the other hand, I cannot believe Gradle would not be flexible enough to achieve that. I hope it is too just hard to find out for me :) ...</p>
  
  <p>Please do not advice me with:</p>
  
  <ul>
  <li>Wrapping other.jar and injecting the mocked variant when running tests (I know that would be possible but it is a lot of extra work which makes no sense to me)</li>
  <li>Attaching the real phone to my Jenkins (I cannot do that as I have no physicall access to Jenkins virtual machine + on a real device I would not be able to control the mock at all)</li>
  <li>Applying other mocking mechanisms like mockito - I also tried this but the other.jar library is not following good design principles therefore it is hard to mock in a standard way - I still did not try powermock but again it makes no sense to me to try if I succeed with the dependencies</li>
  </ul>