Building a Library
Skotch supports multi-module projects where library modules are compiled before application modules and merged into the final output.
Project structure
Section titled “Project structure”myproject/ settings.gradle.kts app/ build.gradle.kts src/main/kotlin/ Main.kt lib/ build.gradle.kts src/main/kotlin/ MathUtils.ktsettings.gradle.kts
Section titled “settings.gradle.kts”rootProject.name = "myproject"include(":app", ":lib")lib/build.gradle.kts
Section titled “lib/build.gradle.kts”plugins { kotlin("jvm")}
group = "com.example"version = "1.0.0"lib/src/main/kotlin/MathUtils.kt
Section titled “lib/src/main/kotlin/MathUtils.kt”fun factorial(n: Int): Int { var result = 1 for (i in 1..n) { result *= i } return result}
fun gcd(a: Int, b: Int): Int { var x = a var y = b while (y != 0) { val temp = y y = x % y x = temp } return x}app/build.gradle.kts
Section titled “app/build.gradle.kts”plugins { kotlin("jvm") application}
group = "com.example"version = "1.0.0"
dependencies { implementation(project(":lib"))}
application { mainClass.set("MainKt")}app/src/main/kotlin/Main.kt
Section titled “app/src/main/kotlin/Main.kt”fun main() { println("5! = ${factorial(5)}") println("gcd(12, 8) = ${gcd(12, 8)}")}Build and run
Section titled “Build and run”cd myprojectskotch buildjava -jar build/example.jar5! = 120gcd(12, 8) = 4Skotch reads settings.gradle.kts to discover modules, resolves
project() dependencies, compiles :lib first, then :app, and
merges all class files into the final JAR.