Home > Software engineering >  Intellij running multiple kotlin files inside project, instead the one selected
Intellij running multiple kotlin files inside project, instead the one selected

Time:09-09

Learning Kotlin and IntelliJ,

Before yesterday if I wanted to run one single .kt file, it was all good. Many ways to do it. I was doing various exercises, all in the same file exercises.kt. After finishing a code, I would just transform it into a comment and start the next one in the same file.

After many exercises, I decided to create a .kt file for each one. But, now, when I run a single file for one exercise Intellij is running ALL files inside the project, instead of just the one I selected.

EDIT: Every .kt file got its own main function, some with a class. To run a single file I used different methods. Clicking the play button at the left of the main function, or clicking the play button at the top bar with the current file selected and clicling with the right button on top of the file in the project list and selecting "Run filekt" (Same as Ctrt shift F10). Like I said before the change explained it was all good.

Here it is my run configuration:

Run Configuration

Content of one of my files that was single running before I changed

fun main() {
    val amanda = Person("Amanda", 33, "play tennis", null)
    val atiqah = Person("Atiqah", 28, "climb", amanda)

    amanda.showProfile()
    atiqah.showProfile()
}

class Person(val name: String, val age: Int, val hobby: String?, val referrer: Person?) {
    fun showProfile() {
        when {
            referrer == null -> println("""Name: ${name}
Age: ${age}
Likes to ${hobby}. Doesn't have a referrer."""")
            else -> println("""Name: ${name}
Age: ${age}
Likes to ${hobby}. Has a referrer named ${referrer.name}, who likes to ${referrer.hobby}""")
        }
    }
}

When Intellij run all the files, this is showing in the project errors. This is new as well. If I try to run the SongCatalog files on Kotlin Playground it's all good.(The Special Auction is in progress)

ProjectError

For the rest of the files, here's the repository: enter image description here

enter image description here

Configure your run configuration the same way as before, except choose the module that you want to run in the "use class path of module" dropdown.

  • Related