Skip to content

πŸ› Amper playground for Kotlin JVM & Multiplatform apps

Notifications You must be signed in to change notification settings

sureshg/kmp-amper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

270 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Kotlin Multiplatform CLI

A Kotlin Multiplatform command-line application targeting macOS, Windows, Linux, and JVM platforms, built with Amper build tools. This project demonstrates a pleasant cross-platform development experience with modern Kotlin tooling.

Usage

# Update the amper
$ ./amper update --dev

# Build the app and create an executable jar
$ ./amper build [-v release]
$ ./amper package

# Run the tests
$ ./amper test

# Run the app
$ ./amper run -m app \
              --jvm-args="--enable-preview --add-modules=jdk.incubator.vector --enable-native-access=ALL-UNNAMED"
$ ./amper run -m macos --platform macosArm64

# JDK Incubator modules
$ ./amper run -m app \
              --jvm-args="--enable-preview --add-modules=jdk.incubator.vector --enable-native-access=ALL-UNNAMED" \
              --main-class=AppKt

# Dependency insights
$ ./amper show dependencies -m app --scope=runtime --filter=org.jetbrains.kotlin:kotlin-stdlib

# Check version updates in amper version catalog
$ brew install deezer/repo/caupain
$ caupain -i libs.versions.toml

# Publish to mavenLocal
$ ./amper publish mavenLocal

# List all the binaries
$ find . \( -path "*/build/*" -type f -perm +111 -o -path "*/build/*executableJar*/*.jar" \) | grep -v -E "(test|debug|dSYM)" | xargs du -h | sort -hr
$ find . \( -path "*/build/*" -perm +111 -o -path "*/build/tasks/*executableJar*/*.jar" \) -type f -ls | awk '{printf "%.3fM %s\n",$7/1048576,$NF}' | sort -rn

Running Binaries

# Run on JVM
$ java --enable-preview \
       --add-modules=jdk.incubator.vector \
       --enable-native-access=ALL-UNNAMED \
       -jar build/tasks/_app_executableJarJvm/app-jvm-executable.jar

# Run on MacOS
$ build/tasks/_macos_linkMacosArm64Release/macos.kexe

# Run on Windows
$ docker run --rm --platform="linux/amd64" \
             -e DISPLAY=host.docker.internal:0 \
             -v "$PWD":/work \
             scottyhardy/docker-wine:latest wine /work/build/tasks/_windows_linkMingwX64Release/windows.exe

# Show MacOS logs
$ log stream --info --style syslog --predicate 'senderImagePath ENDSWITH "macos.kexe"'
$ log show --info --style syslog --predicate 'senderImagePath ENDSWITH "macos.kexe"' --last 5m

Self-Contained Binaries

Package Amper executable JARs with jbundle to create optimized self-contained native bundles.

# Extract JAR contents
$ jar -xf build/tasks/_ktor_executableJarJvm/ktor-jvm-executable.jar

# Note: jarmode layertools not currently supported for Amper JARs
# $ java -Djarmode=layertools -jar build/tasks/_ktor_executableJarJvm/ktor-jvm-executable.jar extract

# Detect required Java modules and build bundle
$ MODULES=$(jdeps -q -R --ignore-missing-deps --print-module-deps --multi-release=25 --class-path "BOOT-INF/lib/*" BOOT-INF/classes)

# Build native bundle (download jbundle from https://github.com/avelino/jbundle/releases/tag/latest)
$ jbundle build --no-appcds \
      --input build/tasks/_ktor_executableJarJvm/ktor-jvm-executable.jar \
      --jvm-args="--enable-preview" \
      --modules $MODULES \
      --output ktor-app  

Tip

You can find all the Amper CLI dev versions here

Amper Config Settings

Configuration πŸ“ Description 🎯 Applies To
settings.kotlin Settings for the Kotlin compiler, thus only apply to Kotlin sources 🟣 Kotlin sources
settings.java Settings for the Java compiler, thus only apply to Java sources β˜• Java sources
settings.jvm Settings that apply to both Java and Kotlin sources (some common compiler options, settings related to the JDK in general, to the test JVM, etc.) πŸ”„ Both Java and Kotlin sources

About

πŸ› Amper playground for Kotlin JVM & Multiplatform apps

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •