https://kotlinlang.org logo
#getting-started
Title
# getting-started
d

Dron Bhattacharya

02/15/2023, 3:11 AM
What is the difference between package and module in Kotlin? I have a python and javascript background.
Which is the first answer on Google for this exact question
d

David Kubecka

02/15/2023, 9:22 AM
I was also kind of confused about the modules. So they are related just to the build step, i.e. there's actually no language construct? If yes what is their relation to the build tools?
m

mkrussel

02/15/2023, 1:03 PM
Modules are the libraries and they produce artifacts like jar, aar, or klib files. Or they could generate apps. As far as the language is concerned, the internal visibility limits access to something to only good in that module. Gradle is the common build script used for Kotlin, and it will normally organize things such that each Gradle project represents a module in Kotlin.
d

David Kubecka

02/15/2023, 2:03 PM
it will normally organize things such that each Gradle project represents a module in Kotlin.
Yeah, I understand that. But what if I do not use Gradle or any build tool at all? How the module is defined then? Or is it just that whatever set of source files is passed to kotlinc constitutes a module?
m

mkrussel

02/15/2023, 2:04 PM
I would guess so. You have to manually do everything the build tool does.
d

David Kubecka

02/15/2023, 2:09 PM
TBC I'm using a built tool 🙂 I'm just trying to understand what's behind the scenes. So my understanding above is confirmed: Module (in contrast to package) is not a language-level construct. This could be perhaps be stressed more in the docs.
m

mkrussel

02/15/2023, 2:20 PM
I would say it is a language construct, because of the
internal
keyword, but it only exists at compile time.
k

Kirill Grouchnikov

02/15/2023, 2:26 PM
Java 9 introduced its own concept of modules
d

David Kubecka

02/15/2023, 2:42 PM
but it only exists at compile time
Exactly, so you cannot see anywhere in the code what a module is (in contrast to package)
69 Views