Is it possible to exclude files from source sets depending on a parameter?


(Matt Turner) #1

Hi all,

I’m trying to get android tests to run conditionally in gradle.

Our Android tests run on real devices. We have some tests specifically for Handset, others for Tablet, and some common tests. I’d like to be able to tell gradle to exclude either the Handset tests, or the Tablet tests - depending on which device we’re testing on.

So far, using gradle 1.10, I have the full test suite running using the following (note, we have a non-standard directory layout which I can’t change for the moment)

androidTest {
      manifest.srcFile 'test/AndroidManifest.xml'
      java {
        srcDir = 'test/src'
      }
      assets.srcDirs = ['test/assets']
    }

This works fine, when I run gradle connectedCheck all of the tests run.

How can I set things up to conditionally exclude some tests ?

I’d like to be able to do something like gradle handsetTest or alternatively gradle -Ptype=handset connectedCheck

which would exclude *TabletTest.java from the androidTest source set.