I can place kotlin code both in `src/kotlin` and `...
# android
p
I can place kotlin code both in
src/kotlin
and
src/java
, what are the benefits in using
src/kotlin
? I guess it's easier to process, but I wan't being able to found any details.
a
It just a sourceSet. Place kotlin files under
src/kotlin
and java file in
src/java
. While this is not a must (as you have noticed), It just makes finding things easier. There are not processing benefits in placing kotlin/java files in one directory over another
☝️ 1
👍 1
a
if you have mixed codebase, I'd just stick with
src/java
, separating classes by language doesn't make any sense to me, but it does cause confusion from time to time for example if you convert a class from java to kotlin you need to remember to move it to
src/kotlin
so there are drawback and I never saw any benefits if you have a kotlin only codebase, then I guess having
src/kotlin
is nicer, since
src/java
makes little sense if there's no java
☝️ 2
2
v
It's imho just cleaner to have them separated. Each language has its own folder and for most languages by default you have to use the language specific folder. Afair JetBrains thought it would be beneficial for incremental adoption if you can mix it in the
java
folder to easier migrate a Java codebase step-by-step and thus made it in their Kotlin plugin so that you can have them in both places. Imho it is totally unclear if you have Kotlin files in a
java
folder. Technically there should not be any difference which you choose, the Kotlin compile task just taskes all Kotlin files from both folders.
1
a
I disagree completely, so I guess "cleaner" is just a matter of personal preference here
v
Always 🙂
Actually the Maven and Gradle inventors think so too as the former invented (or at least conventionalised) this syntax and the latter overtook it and all languages that are supported built-in follow this separation principle by default. It is just the Kotlin plugin where JetBrains decided to use a different default. Well, that's as always not the full truth, as Groovy supports joint compilation where you can freely use the Java classes from Groovy and the Groovy classes from Java, you can indeed also have Java classes in the Groovy folder. But as always, those are only conventions and if you don't like them you are anytime free to change it to whatever you want. If you prefer to have all sources and resources directly under
src
, that's also just a configuration option away.
👍 2