Kotlin/Library Package Maintainer Guide

This page contains useful information for any maintainers of the Kotlin packages' ebuilds.

Kotlin library build process overview
The upstream project uses Gradle as the build system, which handles the building process of the Kotlin libraries automatically. However, as of July 2021, Gradle is not integrated with Portage, and there is not an eclass that can be used to build and package artifacts for a Gradle project easily. Invoking Gradle directly in an ebuild seems to be a feasible solution, but Gradle downloads project dependencies from the Internet on its own, requiring  to be disabled in Portage's FEATURES and preventing any dependencies installed by Portage to be reused, so it is against the best practices.

Instead of relying on Gradle to automatically perform the build steps, the Kotlin library ebuilds directly call the Kotlin compiler and with equivalent compiler options, arguments and list of sources Gradle would use when the upstream project is being built by it. The sequence in which the modules are built and the order of compiler invocations are the same as the upstream project too. Those details about the build process are found through reverse engineering efforts, which will be described in this page below.

A Kotlin library component that is intended to be used with JVM may contain Java sources in addition to Kotlin sources. When such a component is being built, the Kotlin sources will be compiled first, and files will be generated. Then, any Java sources will be compiled by with those  files in the classpath. The files and the class files compiled from Java sources are all the contents in the JAR for the component in most cases. A few components may also have resource files that need to be included in the JAR as well.