Skip to content
skotch
...

Building a Library

Skotch supports multi-module projects where library modules are compiled before application modules and merged into the final output.

myproject/
settings.gradle.kts
app/
build.gradle.kts
src/main/kotlin/
Main.kt
lib/
build.gradle.kts
src/main/kotlin/
MathUtils.kt
rootProject.name = "myproject"
include(":app", ":lib")
plugins {
kotlin("jvm")
}
group = "com.example"
version = "1.0.0"
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
}
plugins {
kotlin("jvm")
application
}
group = "com.example"
version = "1.0.0"
dependencies {
implementation(project(":lib"))
}
application {
mainClass.set("MainKt")
}
fun main() {
println("5! = ${factorial(5)}")
println("gcd(12, 8) = ${gcd(12, 8)}")
}
Terminal window
cd myproject
skotch build
java -jar build/example.jar
5! = 120
gcd(12, 8) = 4

Skotch reads settings.gradle.kts to discover modules, resolves project() dependencies, compiles :lib first, then :app, and merges all class files into the final JAR.