Problems using same OutputDirectory for Kotlin and Java plugins?

Is it a correct approach to use the same OutputDirectory for Kotlin and Java tasks, taking into account that Kotlin compile task should run first and class files produced by it should be passed to the javac classpath? Would it play well with up-to-date checks for both tasks?

The reason why I’m asking is that currently it is the same dir, but we encountered a problem on Android Studio 2 with incremental compilation turned on: in this scenario on the second (incremental) compilation, the kotlin compiler generated files are being deleted from the OutputDir before executing java compiler. (The problem is described in detail here ). So that rises the question whether we are doing it properly with shared OutputDir on the first place.

1 Like

I would expect this to cause issues with up to date checks for incremental. I’d keep the classes directories separate.

On a clean build, the classes directory will ONLY contain kotlin classes after the Kotlin compile. The directory content will be hashed by gradle. Once javac runs the hash will change as classes are added.

Since the hash changes after javac, I would assume the next Kotlin up-to-date check would fail. So Kotlin would compile even if the Kotlin sources haven’t changed.

I do not observe it on my sample projects. Seems that adding anything to OutputDirectory doesn’t trigget compilation.

But assuming that there could be some interferences, like ones described in the problem I mentioned above, how should I merge then kotlin generated classes to java ones? Should I just copy kotlin classes to java task output directory? Or may be I should change java task output to some temporary directory and then copy both outputs to classes dir defined in the source set?