{note}Modules are being redesigned{note}

A *module* is a _unit of compilation_ in [Kotlin]. Physically, modules are described by _build scripts_. Such scripts programmatically assemble _module descriptors_ that carry information about source files that constitute the module, dependencies, and compiler options used to build the module.

Being a unit of compilation means that all the analyses and optimizations may be performed module-wise, and that binary compatibility issues arise only on module boundaries.

h3. Module identifiers and root namespaces

Each module must have a unique identifier. This becomes and identifiers for the module's _root namespace_ -- the one all other namespaces in that module reside in.

h3. Default imports

A build script for a module may specify a set of _default imports_ for its source files. It is convenient to import ubiquitously used libraries (like collections, UI, etc) by default.

h3. Filesystem layout

[Kotlin] does not require any particular layout of source files in the file system: a *namespace* may not correspond to a directory, and a *class* may not occupy its own file. I.e. one can put all the source code for a *module* into a single source file.

h3. Dependencies

Modules can depend on other modules, and specify version requirements for their dependencies.

While exact API is not settled yet, the module script file may look like this:
{jet}
val homeDir = "..."

module("org.jetbrains.test") {
    depends(MavenRepo["junit.junit@4.8.2"])

    importNamespace("java.lang")
    importNamespace("org.junit")

    sourceRoot("$homeDir/src")
    testSourceRoot("$homeDir/tests")
}
{jet}

h3. What's next

* [Packages]