jeudi 23 août 2018

Different Gradle dependency for test than for compile

I am facing this issue with Android/Gradle dependency system

  1. I have quite a complex JAR library with certain API - say other.jar
  2. This other.sdk is completely out of my control
  3. This other.sdk only works on a real phone
  4. I need to write the jUnit tests to be executed on Jenkins (w/o any real phone attached)
  5. Therefore I wrote anothe JAR file called say otherMock.jar
  6. This otherMock.jar has exactly the same API as other.jar

Now I need to do something like this in my build.gradle file:

...

dependencies {
    ...
    testCompile files('libs/otherMock.jar')
    debugCompile files('libs/other.jar')
    releaseCompile files('libs/other.jar')
    ...
}

...

Unfortunately, Gradle seems then to be including both the other.jar and the otherMock.jar within my test build.

I do understand that for majority of builds (including all my previous) it is perfectly desirable behavior.

But for my particular case it is an issue.

I did my best to realize how to configure Gradle to do what I need here, but I failed :(

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 :) ...

Please do not advice me with:

  • 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)
  • 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)

Aucun commentaire:

Enregistrer un commentaire