はじめに
JetBrains 製のJVM向けビルドツール Amper が Kotlin Toolchain としてリブランディングされました。
Amper については以下で簡単に紹介しましたが、あらためて Kotlin Toolchain として使い方を見ていきましょう。
Kotlin Toolchain では、ビルドスクリプトを yaml で宣言的に定義し、JVMライブラリ/JVMアプリケーション、Kotlinライブラリ/Kotlinアプリケーション、Kotlin Multiplatform アプリケーションなどのビルドが可能です。
Kotlinマルチプラットフォームプロジェクトのビルドが第一ターゲットとなっていますが、Java プロジェクトにも普通に使えます。
現在バージョンは 0.11.0 でアルファ版段階ですが、最近の Gradle はアレなので、乗り換え先として検討するのも良いでしょう。
インストール
Amper はラッパースクリプト(Gradle で言う gradlew)をダウンロードして実行する形でしたが、Kotlin Toolchain では CLI をインストールする形になりました。 もちろん gradlew や mvnw と同様に、ラッパースクリプトの配置されたプロジェクトをビルドするだけなら、CLIのインストールは不要です。
macOS / Linux の場合は以下でインストールできます。
curl -fsSL https://kotl.in/install.sh | sh
Windows の場合は以下でインストールできます。
powershell -ExecutionPolicy ByPass -c "irm 'https://kotl.in/install.ps1' | iex"
SDKMAN で以下のように導入することもできます。
sdk install kotlintoolchain
インストーラースクリプトは、Kotlin CLIラッパーとCLIランタイムをダウンロードし、以下のディレクトリに配備し、CLIラッパーのディレクトリをPATHに追加します。
| OS | CLIラッパー | キャッシュディレクトリ |
|---|---|---|
| macOS | $HOME/.local/bin |
$HOME/Library/Caches/JetBrains/Kotlin/cli |
| Linux | $HOME/.local/bin |
$HOME/.cache/JetBrains/Kotlin/cli |
| Windows | %USERPROFILE%\.local\bin |
%LOCALAPPDATA%\JetBrains\Kotlin\cli |
バージョン確認は以下となります。
kotlin --version Kotlin Toolchain version 0.11.0 (35ef359, 2026-05-20)
CLI のアップデートは以下で行います。
kotlin update
ヘルプは以下のように確認できます。
kotlin --help
Usage: kotlin [<options>] <command> [<args>]...
Options:
-v, --version Show the version and exit
--root=<path> Kotlin project root (deprecated)
--log-level=(debug|info|warn|error|off) Console logging level (default: INFO)
--shared-cache-dir=<path> Path to the cache directory shared between all Kotlin projects (default:
C:\Users\User\AppData\Local\JetBrains\Kotlin)
--shared-caches-root=<path> Path to the cache directory shared between all Kotlin projects (deprecated)
--build-output=<path> Root directory for build outputs. By default, this is the build directory
under the project root. (deprecated)
-h, --help Show this message and exit
Debugging options:
--profile Profile the Kotlin CLI with the Async Profiler. The path to the snapshot file is
determined by --profiler-snapshot-path.
--profiler-snapshot-path=<path> The output path for the snapshot file generated by the profiler. (default:
async-profiler-snapshot-2026-07-31_15-21-45-5568.jfr)
--coroutines-debug Enable coroutines debug probes. This allows to dump the running coroutines in case of
deadlock.
Commands:
build Compile and link all code in the project
check Run checks in the project
clean Remove the project's build output and caches
clean-shared-caches Remove the caches that are shared between projects
do Run a custom command
generate-completion Generate a tab-completion script for the Kotlin CLI for the given shell (bash, zsh, or fish)
init Initialize a new Kotlin project based on a template
package Package the project artifacts for distribution
publish Publish modules to a repository
run Run your application
show Show information about some aspect the project (modules, tasks, effective settings...). See help
for details.
task Run a task and its dependencies from the task graph
test Run tests in the project
tool Run a tool
update Update the Kotlin Toolchain to the latest version or a specific version.
プロジェクトの作成
主なコマンドは以下となり、多くのビルドツールと大差ありません。
| コマンド | 説明 |
|---|---|
kotlin init |
新しいプロジェクトを作成する |
kotlin build |
プロジェクト内のすべてのコードをコンパイルしてリンクする |
kotlin run |
アプリケーションを実行する |
kotlin test |
プロジェクトでテストを実行する |
kotlin show |
プロジェクトの構成を調査する |
kotlin clean |
プロジェクトのビルド出力とキャッシュを削除する |
新しいプロジェクトを作成してみましょう。
mkdir example && cd example kotlin init
以下のようなテンプレート選択画面になります。
Select a project template:
❯ Android application (Jetpack Compose)
An Android application using Jetpack Compose for its UI
Compose Multiplatform application
A KMP project with Android, iOS, and JVM desktop applications sharing UI with Compose Multiplatform
iOS application (Compose Multiplatform)
An iOS application using Compose Multiplatform for iOS for its UI
JVM console application
A plain JVM console application without any framework
JVM GUI application (Compose Multiplatform)
A JVM application using Compose Multiplatform for Desktop for its UI
Kotlin Multiplatform library
A multiplatform library targeting Android, iOS, and the JVM
Ktor server application
A Ktor server application with the Netty engine
Multiplatform CLI application
A multiplatform CLI application targeting the JVM, as well as Linux, macOS, and Windows native targets
Spring Boot application (Java)
A Spring Boot application written in Java
Spring Boot application (Kotlin)
A Spring Boot application written in Kotlin
ここでは JVM console application を選択しました。
以下のようなフォルダ構成となります。
example
├ kotlin
├ kotlin.bat
├ module.yaml
├ src
│ ├ main.kt
│ └ World.kt
└ test
└ WorldTest.kt
module.yaml が構成ファイルで以下のようになります。
product: jvm/app
プロダクトタイプには現在以下のものを指定可能となっています。
| Product type(s) | Description |
|---|---|
jvm/lib |
A JVM library |
jvm/app |
A JVM console or desktop application |
kmp/lib |
A Kotlin Multiplatform library |
windows/app |
A Kotlin/Native mingw-w64 application |
linux/app |
A Kotlin/Native Linux application |
macos/app |
A Kotlin/Native macOS application |
android/app |
An Android application |
ios/app |
An iOS application |
js/app |
A JavaScript application using the Kotlin/JS technology |
wasmJs/app |
A WebAssembly application with browser APIs |
wasmWasi/app |
A WebAssembly application with WASI APIs |
jvm/amper-plugin |
A Kotlin Toolchain plugin, to extend the Kotlin Toolchain build with custom functionality |
サンプルプロジェクトのビルド
簡単なJavaアプリケーションのビルドを行いましょう。
以下のような構成とします。
example
├ kotlin
├ kotlin.bat
├ module.yaml
├ src
│ └ example
│ └ Main.java
└ test
└ example
└ Main.java
Main.java は以下のようにします。
package example; import org.apache.commons.lang3.RandomStringUtils; public class Main { public static void main(String[] args) { System.out.println(hello()); System.out.println(RandomStringUtils.secure().nextNumeric(6)); } public static String hello() { return "Hello World!"; } }
MainTest.java は以下のようにします。
package example; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; public class MainTest { @Test void test() { assertEquals(Main.hello(), "Hello World!"); } }
module.yaml は以下のようにします。
product: jvm/app dependencies: - org.apache.commons:commons-lang3:3.20.0 settings jvm: mainClass: example.Main jdk: version: 25
commons-lang3 の依存を追加しました。
依存関係のスコープは、compile-only または runtime-only を指定することもでき、以下のように指定します。
dependencies: - org.apache.commons:commons-lang3:3.20.0: compile-only
settings でメインクラスとJDKのバージョンを指定しています。
JDKは(存在しない場合は)自動的にダウンロードしてプロビジョニングされます。
指定しない場合、現在は JDK 21 がデフォルトとなります。
ビルドは以下のようになります。
./kotlin build Build successful
実行してみましょう。
./kotlin run Hello World! 919867 00:01.814 INFO :example:runJvm Process exited with exit code 0
テストを実行してみましょう。
./kotlin test 00:02.339 INFO :example:testJvm Testing module 'example' for platform 'jvm'... Started MainTestStarted test() Passed test() Test run finished after 173 ms [ 4 containers found ] [ 0 containers skipped ] [ 4 containers started ] [ 0 containers aborted ] [ 4 containers successful ] [ 0 containers failed ] [ 1 tests found ] [ 0 tests skipped ] [ 1 tests started ] [ 0 tests aborted ] [ 1 tests successful ]
テストフレームワークは各プラットフォーム向けに事前設定されているため、特に設定する必要はありません。 テスト専用の追加の依存関係は、以下のように指定します。
test-dependencies: - org.mockito:mockito-core:5.23.0
プロジェクトレイアウト
単一モジュールプロジェクト
単一モジュールの場合は、ルートに module.yaml が必要です。
example ├ src │ └ example │ └ Main.java ├ resources │ └ logback.xml │ ├ test │ └ example │ └ Main.java ├ testResources │ └ logback.xml │ ├ kotlin ├ kotlin.bat └ module.yaml
マルチモジュールプロジェクト
マルチモジュールの場合は、ルートに project.yaml が必要です。
example ├ app │ ├ src │ │ ├ Main.java │ │ └ ... │ └ module.yaml ├ libs │ ├ lib1 │ │ ├ src │ │ │ └ Lib1.java │ │ └ module.yaml │ └ lib2 │ ├ src │ │ └ Lib2.java │ └ module.yaml ├ kotlin ├ kotlin.bat └ project.yaml
project.yaml では以下のようにモジュールのリストを指定します。
modules: - app - libs/lib1 - libs/lib2