What is the difference between package and module ...
# getting-started
d
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
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
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
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
I would guess so. You have to manually do everything the build tool does.
d
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
I would say it is a language construct, because of the
internal
keyword, but it only exists at compile time.
k
Java 9 introduced its own concept of modules
d
but it only exists at compile time
Exactly, so you cannot see anywhere in the code what a module is (in contrast to package)
128 Views