1

I'm learning kotlin recently and have experience with python and pycharm. I'm having some problems on importing a file as a source root in IntelliJ IDE.

my problems are,

  1. If I keep my custom .kt file say calculation.kt in the same folder as main.kt i.e..$project$/src/main/kotlin/main.kt file directory I don't have to import or add calculation.kt in main.kt. All functions within the calculation.kt works fine, maybe being implicitly imported.

  2. But if I keep the file in another folder i.e $project$/src/others/calculation.kt and mark the "others" folder as the source root, yet the calculation.kt doesn't get implicitly imported. Maybe I need to do an explicit import of calculation.kt in my main.kt. I need to know how to do that

  3. Do I have to do any addition to build.gradle.kts file? I think I have to do some inclusion in there, please share an example on that.

Thank you.

project setup in intellij

ndc85430
  • 1,395
  • 3
  • 11
  • 17
Shams313
  • 71
  • 6
  • 1
    Why do you want to do that? Is there a reason you're not putting everything under `src/main/kotlin`? – ndc85430 Jun 05 '22 at 04:24
  • nah, it works fine if I put it there, but there must be a way to include another folder as a source root, bcz this I always prefer to do, keep the project organized and clean – Shams313 Jun 05 '22 at 04:28
  • 1
    The standard way to organise things in Kotlin projects is to use packages, under `src/main/kotlin`. I suggest sticking with the conventions instead of artificially making things more complicated. – ndc85430 Jun 05 '22 at 04:30

0 Answers0