2

I wish to exclude a Kotlin file from my build.

Trying something like:

sourceSets {
    main {
        kotlin {
            exclude '**/Test.kt'
        }
    }
}

Doesn't work, the file gets compiled.

I have searched endlessly and similar questions on StackOverflow have no working answer and zero activity, and it's hard to believe that such a simple goal is so hard to achieve.

SirKnigget
  • 3,614
  • 2
  • 28
  • 61
  • 1
    maybe not comment you want, but why do you have `.kt` files in your sources you don't want to compile? – al3c Sep 23 '20 at 09:53
  • @al3c I need to be able to easily exclude some files without deleting / restoring them and messing my version control – SirKnigget Sep 23 '20 at 15:31
  • See https://discuss.kotlinlang.org/t/how-to-exclude-kotlin-files-from-compiling-with-gradle/17018 – Alex Cohn Sep 24 '20 at 07:45
  • @AlexCohn The link you added does not contain any working answer. – SirKnigget Oct 04 '20 at 17:20
  • Oh, I know the link does not contain a *working answer*. The problem is, this is **the answer** up to date. Has a new/better answer than https://stackoverflow.com/a/54398253 become available since January 2019? OTH, in what is your *question* different from *[How to exclude kotlin files from compiling with gradle](https://stackoverflow.com/questions/54376686/how-to-exclude-kotlin-files-from-compiling-with-gradle)*? I know that SO is sometimes disappointing, but it cannot pull a miraculous answer out of the hat, when there has never been a rabbit inside. – Alex Cohn Oct 05 '20 at 14:38
  • @alexcohn In this case, create an answer that says "this is impossible" and mark as the accepted answer. – SirKnigget Oct 06 '20 at 05:42
  • I read the upvoted answer, and it says exactly this, and even proposes kind of a workaround. – Alex Cohn Oct 06 '20 at 06:37
  • @AlexCohn So mark it as the accepted answer (it's impossible to exclude files from build), if I knew that clearly I certainly wouldn't have to ask this question again... Right now the previous SO questions are dead and don't give any clear direction about this matter. – SirKnigget Oct 06 '20 at 10:07
  • I can only accept an answer on a question that is mine. Alas, [@HeyAlex](https://stackoverflow.com/users/4826038/heyalex) is not myself. – Alex Cohn Oct 06 '20 at 10:31

0 Answers0