Kotlin

Kotlin is [[Article description::a programming language developed by JetBrains]]. Originally shaped as a programming language based on the Java platform and JVM, Kotlin was designed with Java interoperability in mind, meaning that a Kotlin program can use not just the Kotlin Standard Library but the Java SE API and all Java libraries too, and Java programs can call useful helpers in the Kotlin Standard Library and all sorts of other Kotlin code as well. Later, Kotlin has been expanded with Android support, JavaScript support through Kotlin/JS, and support for native machine code as compiler target via Kotlin/Native.

Like virtually all other GNU/Linux distributions, Gentoo does not provide Kotlin in its official ebuild repository. A few users' personal ebuild repositories may contain an ebuild for Kotlin that unpacks the compiler Zip archive made by the upstream to the file system. During Google Summer of Code 2021, ebuilds that can build the Kotlin core libraries were created, so Gentoo users can install the Kotlin libraries from source instead of binaries pre-compiled by the upstream.

Available packages
The following packages for Kotlin are available:

Versioning and package slotting
The Kotlin packages strive to stay consistent with the upstream's versioning scheme. Here is the glossary of terms the upstream uses to define the versioning scheme and describe different kinds of Kotlin releases:


 * Feature releases, e.g. 1.3, 1.4, 1.5...: Incompatible API changes are expected. For example, several compiler warnings have been promoted to compiler errors in Kotlin 1.5.
 * Incremental releases, e.g. 1.5.0, 1.5.10, 1.5.20...: Small but non-trivial changes are expected; however, they should be API compatible with prior versions in the same feature release series. For example, in the upstream's Kotlin compiler Zip archive for Kotlin 1.5.20, a new Lombok compiler plugin JAR was added.
 * Bug fix releases, e.g. 1.4.30, 1.4.31, 1.4.32...: As the name suggests, this kind of releases usually contains minor fixes only.

All Kotlin library packages are slotted based on the feature releases, so users can specify to install libraries for Kotlin 1.4.x, 1.5.x, etc. and use libraries for multiple different feature releases in parallel. However, dev-lang/kotlin-bin is not slotted yet, so only one version of the compiler can be installed on the system at a time.

Ebuild repository
The Kotlin ebuilds are currently located in Leo3418's fork of the Spark overlay originally created during GSoC 2020. It is configured as:

Instead of editing the file directly, the repository can be set up with :

Since this is a Git-based ebuild repository, please ensure is installed on the system before syncing it:

Then, the repository's contents can be synchronized to the system:

dev-java/kotlin-* packages
Each of the Kotlin library packages provides some or all of the USE flags listed below:


 * : Use the binary JAR pre-built by the upstream instead of compile the package from source
 * : Install an archive of the source files under, so the package's source files can be viewed from some IDEs
 * : Enable dependencies to run the package's tests, which are controlled by

dev-lang/kotlin-bin
The Kotlin compiler package has a USE flag for installing with optional Kotlin/JS support.

Emerge
To compile the Kotlin libraries from source, the Kotlin compiler, which is provided by dev-lang/kotlin-bin, must be installed first. However, the compiler depends on two components from the Kotlin libraries, namely kotlin-stdlib and kotlin-reflect, so the two components must be bootstrapped before the remaining packages for Kotlin are installed.

dev-java/kotlin-stdlib and dev-java/kotlin-reflect both recognize the  USE flag, which should be enabled when they are to be installed before dev-lang/kotlin-bin has been merged. The USE flag can be temporarily enabled via the USE environment variable.

Then, the Kotlin compiler can be merged:

Finally, dev-java/kotlin-stdlib and dev-java/kotlin-reflect can be rebuilt from source with the compiler installed just now:

The compiler can now be used to build all other Kotlin library packages for Java and JVM from source as well.

Using the upstream's pre-built binaries
If use of the upstream's pre-built binaries is acceptable for some or all of the Kotlin library packages, the  USE flag can be permanently enabled for them so they will not be built from source. The following example demonstrates how to enable the USE flag for select Kotlin packages:

Kotlin/JS
To install Kotlin with Kotlin/JS support, please enable the  USE flag for dev-lang/kotlin-bin. This makes dev-lang/kotlin-bin depend on dev-java/kotlin-stdlib-js, but the latter package also requires the Kotlin compiler if it is to be built from source. Thus, dev-java/kotlin-stdlib-js needs to be bootstrapped with dev-java/kotlin-stdlib and dev-java/kotlin-reflect together in this case:

Installing an old feature release
The steps listed above install the latest version of Kotlin available in the Spark overlay. The overlay might provide ebuilds for multiple feature releases of Kotlin, and an older release can be installed using instructions in this section.

Installing an old version of both the compiler and the libraries
The dev-lang/kotlin-bin package is not slotted yet, so in order to install the package for an old feature release and prevent it from being updated, versions for newer feature releases need to be masked. To use the compiler for one feature release, mask all versions of dev-lang/kotlin-bin for the next feature release and above, so any bug fixes and security updates for the old feature release can still be pulled and installed.

Then, when bootstrapping kotlin-stdlib and kotlin-reflect (and kotlin-stdlib-js if the  USE flag is enabled for dev-lang/kotlin-bin), specify the feature release's version with the slot name. For example, to install libraries for Kotlin 1.4:

Now, the Kotlin compiler can be merged with the same command, and should prompt that a version of dev-lang/kotlin-bin for the old feature release is being installed.

Finally, the libraries can be rebuilt from source. The slots for the library packages need to be specified here as well:

Installing an old version of the libraries only
As long as a version of dev-lang/kotlin-bin has been merged, the Kotlin compiler should be able to be used for building library packages for older Kotlin feature releases still supported by the compiler. As a rule of thumb, the last version each recent Kotlin feature release supports is the one that is two feature releases behind it:

Assuming a compiler that supports the desired feature release version of the libraries has already been installed, the libraries can be merged directly. Remember to specify the libraries' version via the slot name. For example, to install kotlin-stdlib-jdk8 and kotlin-test-junit for Kotlin 1.4:

Installing an old version of the compiler only
It is not possible to have only the compiler for a feature release installed because dev-lang/kotlin-bin depends on dev-java/kotlin-stdlib and dev-java/kotlin-reflect for the same version. Nevertheless, users who wants to use an older version of the compiler but a newer version of the libraries can still elect to install the old version of the compiler with the same old version of the libraries, then enable the  USE flag for the newer version of the libraries.