'What's the difference between .kt and .kts files in Kotlin. When should we use .kts file over .kt file?

What is the purpose of using .kts files in Kotlin? Are these files included in the app bundle when releasing the app?

enter image description here



Solution 1:[1]

.kt — normal source files, .kts — script files

You don't need the main function in a .kts file, It will be executed line by line just like a bash/python script.

The .kts files don't a need for separate compilation. it is run using the following command:

kotlinc -script <filename>.kts

Solution 2:[2]

.Kt and .Kts

  • They are all kotlin files that contain kotlin source code.
  • .kt file are assumed to be compiled by the kotlin compiler.
  • .Kts files are assumed to be executed by kotlin scriting support.

As Explained in kolinConf18

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2