Understanding modules


#1

Hello.

I’m reading the kotlin reference about visibility modifiers. There are a lot of references to the term “module” but I couldn’t find anything about what the module is.
There are some information on the “http://confluence.jetbrains.com/”. It starts from the fact that modules are beeing redesigned now.

Are there any docs on “modules”?
How can feel the difference between internal and public modifiers?

Regards, Alexey


#2

Modules are those things you break a project into at design time. Kotlin module maps one-to-one to IntelliJ's module (iml-file). Kotlin M8 does not respect modules yet (M9 will), so you can't see the difference between public and internal yet, but it will come :) Sorry for the inconvenience


#3

Kotlin module maps one-to-one to IntelliJ's module (iml-file).

And what about comand line compilation or a maven project (if there are no any IDE specific files inside)?


#4

Each compiler run, by default, is a separate module: all the binary dependencies will be treated as being not in the module being compiled at the moment.


#5

Got it! Thanks!


#6

Does this mean that the internal modifier is only checked by the compiler but there are no guarantees at runtime?


#7

Where possible the system does name mangling to make it harder to use it invalidly. But remember that at runtime there are no guarantees even for private members (you can open them up using reflection). Accidental usage from Java is prevented though.


#8

This helped me from an Android Development point of view:

A module is a set of Kotlin sources compiled together:

  • an IntelliJ IDEA module;
  • a Maven project;
  • a Gradle source set (with the exception that the test source set can access the internal declarations of main);
  • a set of files compiled with one invocation of the Ant task.
    (from the Kotlin Reference Documentation)

That means that if you have different build flavours in your gradle configuration resulting in different source sets (for production and debug versions for example) , then an internal class from one source set wouldn’t be available to be used in another source set.

That’s my take from the topic.