# Is there a way to only apply Kotlin for unit tests

**URL:** <https://discuss.kotlinlang.org/t/is-there-a-way-to-only-apply-kotlin-for-unit-tests/1524>\
**Category:** Android\
**Created:** [March 11, 2016, 9:04am UTC](https://discuss.kotlinlang.org/t/is-there-a-way-to-only-apply-kotlin-for-unit-tests/1524 "2016-03-11T09:04:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dalewking](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/dalewking/32/1496_2.png) [@dalewking](https://discuss.kotlinlang.org/u/dalewking)\
**Post date:** [March 11, 2016, 9:04am UTC](https://discuss.kotlinlang.org/t/is-there-a-way-to-only-apply-kotlin-for-unit-tests/1524/1 "2016-03-11T09:04:54Z")

</div>

We have been told not to use Kotlin for the production code of our app, but there is no reason why we couldn’t use it in unit tests, so am wondering if there is an easy way to configure the gradle plugin for Android such that Kotlin is only supported in unit tests and will not compile for the main code?

---

<div class="post-metadata">

**Author:** ![hotchemi](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/hotchemi/32/1760_2.png) [@hotchemi](https://discuss.kotlinlang.org/u/hotchemi)\
**Post date:** [March 11, 2016, 10:56am UTC](https://discuss.kotlinlang.org/t/is-there-a-way-to-only-apply-kotlin-for-unit-tests/1524/2 "2016-03-11T10:56:48Z")

</div>

Isn’t it enough to use testCompile for declaring Kotlin dependency if you are using Gradle?

---

<div class="post-metadata">

**Author:** ![dalewking](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/dalewking/32/1496_2.png) [@dalewking](https://discuss.kotlinlang.org/u/dalewking)\
**Post date:** [March 11, 2016, 12:47pm UTC](https://discuss.kotlinlang.org/t/is-there-a-way-to-only-apply-kotlin-for-unit-tests/1524/3 "2016-03-11T12:47:44Z")

</div>

> [@hotchemi](#):
>
> Isn’t it enough to use testCompile for declaring Kotlin dependency if you are using Gradle?

Nope, it can still compile kotlin files in the main source directories.

---

<div class="post-metadata">

**Author:** ![Natalia.Ukhorskaya](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/natalia.ukhorskaya/32/1447_2.png) [@Natalia.Ukhorskaya](https://discuss.kotlinlang.org/u/Natalia.Ukhorskaya)\
**Post date:** [March 11, 2016, 1:38pm UTC](https://discuss.kotlinlang.org/t/is-there-a-way-to-only-apply-kotlin-for-unit-tests/1524/4 "2016-03-11T13:38:48Z")

</div>

You can configure source sets for kotlin using src.main.kotlin (or test). By default they are equal to src.main.java + “src/main/kotlin”

---

<div class="post-metadata">

**Author:** ![dalewking](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/dalewking/32/1496_2.png) [@dalewking](https://discuss.kotlinlang.org/u/dalewking)\
**Post date:** [March 11, 2016, 6:52pm UTC](https://discuss.kotlinlang.org/t/is-there-a-way-to-only-apply-kotlin-for-unit-tests/1524/6 "2016-03-11T18:52:31Z")

</div>

> [@Natalia.Ukhorskaya](#):
>
> You can configure source sets for kotlin using src.main.kotlin (or test). By default they are equal to src.main.java + “src/main/kotlin”

Using your information here is a working solution:

```
afterEvaluate {
   android.sourceSets.all { sourceSet ->
      if (!sourceSet.name.startsWith("test"))
      {
         sourceSet.kotlin.setSrcDirs([])
      }
   }
}

```
