以下の内容はhttps://blog1.mammb.com/entry/2026/01/01/000000より取得しました。


Gradle に疲れた人のためのビルドツール Amper

最近 Gradle に疲れを感じます。

  • 頻繁な更新で、現在の正しい書き方が分からない
  • 頻繁にAPIが更新され、プラグインがすぐに動かなくなる
  • たくさんの設定ファイルがあり、どこに何をかけばよいのか分からなくなる
  • 機能追加/変更を追いきれないし、ネットの情報も陳腐化している
  • 公式ドキュメントがわかりにくい

そんなあなたは、Amper を試してみると良いかもしれません。

まだバージョンは 0.9 ですが。


Amper とは

JetBrains が提供する実験的なプロジェクト構成ツールです。

github.com

特徴として以下が謳われています。

  • 宣言型設定DSLの提供
    • 初期設定の簡素化だけでなく、保守性を向上させ、IDEによる自動設定の信頼性を高める
  • 厳選されたツールチェーンのバンドル -- 互換性のあるプラグインを探す必要なく、大半のシナリオをサポートする
  • 拡張ポイントの慎重な選定 -- 設定の全体的なメンタルモデルとUXの一貫性を保ち、予期せぬサードパーティコードの実行を回避する

build.gradle.kts を yaml で書く、シンプルな Gradle といった趣です。

Gradle は、ビルドスクリプトを宣言型に定義することを目指したものですが、現実的にはビルドスクリプトに命令型コードが混在し、複雑なビルドスクリプトになりがちです。

Amper では、yaml でビルド定義を宣言的に行うことを強制しているんだと思います。


Amper の導入

プロジェクトフォルダを作成して以下のように導入します。

mkdir example && cd example
curl -fsSL -o amper https://jb.gg/amper/wrapper.sh && chmod +x amper && ./amper update -c

Windows 環境の場合は curl の代わりに以下を実行します。

Invoke-WebRequest -OutFile amper.bat -Uri https://jb.gg/amper/wrapper.bat; ./amper update -c

以下のようにインストールが行われます。

*** Welcome to Amper v.0.9.2! ***

This is the first run of this version, so we need to download the actual Amper distribution.
Please give us a few seconds now, subsequent runs will be faster.

Downloading Amper distribution v0.9.2...
Download complete.

Downloading Amper runtime v25.28.85...
Download complete.

Fetching latest Amper version info...
Latest Amper version is 0.9.2
Downloading Amper scripts...
Download complete.
JetBrains Amper version 0.9.2 (80094bb, 2025-12-11)
Update successful

プロジェクトフォルダにAmper起動用のシェルスクリプトamper (とWindows用のamper.bat) が作成されると伴に、以下のディレクトリに Amper の実行モジュールがダウンロードされます(環境変数 AMPER_BOOTSTRAP_CACHE_DIR で変更可能)。

OS キャッシュディレクトリ
macOS $HOME/Library/Caches/JetBrains/Amper
リナックス $HOME/.cache/JetBrains/Amper2
ウィンドウズ %LOCALAPPDATA%\JetBrains\Amper


Amper の使い方

ヘルプは以下のようになっています。

$ ./amper --help

Usage: amper [<options>] <command> [<args>]...

Options:
  -v, --version                            Show the version and exit
  --root=<path>                            Amper project root
  --log-level=(debug|info|warn|error|off)  Console logging level (default: INFO)
  --shared-caches-root=<path>              Path to the cache directory shared between all Amper projects (default:
                                           C:\Users\User\AppData\Local\JetBrains\Amper)
  --build-output=<path>                    Root directory for build outputs. By default, this is the build directory
                                           under the project root.
  -h, --help                               Show this message and exit

Debugging options:
  --profile           Profile Amper with the Async Profiler. The snapshot file is generated in the build logs.
  --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
  clean                Remove the project's build output and caches
  clean-shared-caches  Remove the Amper caches that are shared between projects
  generate-completion  Generate a tab-completion script for the Amper command for the given shell (bash, zsh, or fish)
  init                 Initialize a new Amper 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 Amper to the latest version

大まかに以下を覚えておけば問題ありません。

コマンド 説明
amper init 新しいAmperプロジェクトを作成する
amper build プロジェクト内のすべてのコードをコンパイルしてリンクする
amper run アプリケーションを実行する
amper test プロジェクトでテストを実行する
amper show (modules|settings|dependencies|tasks)プロジェクトの構成を調査する
amper clean プロジェクトのビルド出力とキャッシュを削除する


プロジェクトの初期化

amper init でプロジェクトを初期化します。

現在は、以下のテンプレートから選択できます。

$ ./amper 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
↑ up • ↓ down • enter select

ここでは、JVM console application を選択しました。

以下のようなフォルダ構成になります。

example
 ├─ amper
 ├─ amper.bat
 ├─ module.yaml
 ├─ src
 │   ├─ main.kt
 │   └─ World.kt
 └─ test
     └─ WorldTest.kt

module.yaml が Amper の設定ファイルで、以下のような内容となっています。

product: jvm/app

product タイプは以下が用意されています(gradle で java プラグインを指定するようなものと捉えると良いでしょう)。

Product type(s) Description
jvm/lib JVM ライブラリ
jvm/app JVM コンソール/デスクトップアプリケーション
lib Kotlin マルチプラットフォームライブラリ
windows/app Kotlin/Native mingw-w64 アプリケーション
linux/app A Kotlin/Native Linux アプリケーション
macos/app A Kotlin/Native macOS アプリケーション
android/app Android アプリケーション
ios/app iOS アプリケーション
js/app JavaScript アプリケーション(Kotlin/JS利用)
wasmJs/app WebAssembly アプリケーション(ブラウザAPI利用)
wasmWasi/app WebAssembly アプリケーション(WASI API利用)
jvm/amper-plugin Amper プラグイン

ひな形コードは以下が生成されます。

main.kt

fun main() {
    println("Hello, ${World.get()}!")
}

World.kt

object World {
    fun get(): String {
        return "World";
    }
}

WorldTest.kt

import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue

class WorldTest {
    @Test
    fun doTest() {
        assertEquals("World", World.get())
    }

    @Test
    fun shouldFail() {
        assertTrue(false)
    }
}

JavaファイルとKotlinファイルは一緒に配置できます。 リソースファイルを含む場合は以下のようなレイアウトになります。

my-module/
├─ resources/ 
│   └─ logback.xml 
├─ src/
│   ├─ main.kt
│   └─ Util.java 
├─ test/
│   └─ MainTest.java 
│   └─ UtilTest.kt
├─ testResources/
│   └─ logback-test.xml 
└─ module.yaml


ビルドと実行

ビルドしてみましょう。

$ ./amper build
00:24.962 INFO  :example:compileJvm       Downloading https://corretto.aws/downloads/resources/21.0.1.12.1/amazon-corretto-21.0.1.12.1-windows-x64-jdk.zip to C:\Users\User\AppData\Local\JetBrains\Amper\download.cache\5de2c13edf-amazon-corretto-21.0.1.12.1-windows-x64-jdk.zip
01:10.228 INFO  :example:compileJvm       Compiling module 'example' for platform 'jvm'...
01:13.014 INFO  :example:compileJvmTest   Compiling module 'example' for platform 'jvm'...
Build successful

初回なので、JDKがダウンロードされます。

実行してみましょう。

$ ./amper run
Hello, World!
00:02.568 INFO  :example:runJvm           Process exited with exit code 0

テストも実行してみましょう。

初回なので、Junit がダウンロードされます。

$ ./amper test
00:02.479 INFO  :example:testJvm          Downloading https://repo1.maven.org/maven2/org/junit/platform/junit-platform-console-standalone/6.0.1/junit-platform-console-standalone-6.0.1.jar to C:\Users\User\AppData\Local\JetBrains\Amper\download.cache\9a47b1e632-junit-platform-console-standalone-6.0.1.jar
00:03.844 INFO  :example:testJvm          Testing module 'example' for platform 'jvm'...
Started WorldTest
Started doTest()
Passed doTest()
Started shouldFail()
Failed shouldFail()
           => Exception: org.opentest4j.AssertionFailedError: Expected value to be true.
                at org.junit.jupiter.api.AssertionUtils.fail(AssertionUtils.java:42)
                at org.junit.jupiter.api.Assertions.fail(Assertions.java:143)
                at kotlin.test.junit5.JUnit5Asserter.fail(JUnitSupport.kt:56)
                at kotlin.test.Asserter.assertTrue(Assertions.kt:694)
                at kotlin.test.junit5.JUnit5Asserter.assertTrue(JUnitSupport.kt:30)
                at kotlin.test.Asserter.assertTrue(Assertions.kt:704)
                at kotlin.test.junit5.JUnit5Asserter.assertTrue(JUnitSupport.kt:30)
                at kotlin.test.AssertionsKt__AssertionsKt.assertTrue(Assertions.kt:44)
                at kotlin.test.AssertionsKt.assertTrue(Unknown Source)
                at kotlin.test.AssertionsKt__AssertionsKt.assertTrue$default(Assertions.kt:42)
                at kotlin.test.AssertionsKt.assertTrue$default(Unknown Source)
                at WorldTest.shouldFail(WorldTest.kt:13)

Failures (1):
  JUnit Jupiter:WorldTest:shouldFail()
    MethodSource [className = 'WorldTest', methodName = 'shouldFail', methodParameterTypes = '']
    => org.opentest4j.AssertionFailedError: Expected value to be true.
       org.junit.jupiter.api.AssertionUtils.fail(AssertionUtils.java:42)
       org.junit.jupiter.api.Assertions.fail(Assertions.java:143)
       kotlin.test.junit5.JUnit5Asserter.fail(JUnitSupport.kt:56)
       kotlin.test.Asserter.assertTrue(Assertions.kt:694)
       kotlin.test.junit5.JUnit5Asserter.assertTrue(JUnitSupport.kt:30)
       kotlin.test.Asserter.assertTrue(Assertions.kt:704)
       kotlin.test.junit5.JUnit5Asserter.assertTrue(JUnitSupport.kt:30)
       kotlin.test.AssertionsKt__AssertionsKt.assertTrue(Assertions.kt:44)
       kotlin.test.AssertionsKt.assertTrue(Unknown Source)
       kotlin.test.AssertionsKt__AssertionsKt.assertTrue$default(Assertions.kt:42)

Test run finished after 275 ms
[         4 containers found      ]
[         0 containers skipped    ]
[         4 containers started    ]
[         0 containers aborted    ]
[         4 containers successful ]
[         0 containers failed     ]
[         2 tests found           ]
[         0 tests skipped         ]
[         2 tests started         ]
[         0 tests aborted         ]
[         1 tests successful      ]


ERROR: JVM tests failed for module 'example' with exit code 1 (see errors above)

ひな形のテストコードは、常に失敗するメソッドがあるので、Failed となります。


依存関係の追加

module.yaml に dependencies を追加します。

product: jvm/app

dependencies:
  - org.jetbrains.kotlinx:kotlinx-datetime:0.6.2

main.kt で datetime を使ってみましょう。

import kotlinx.datetime.*

fun main() {
    println("Hello, World!")
    println("It's ${Clock.System.now().toLocalDateTime(TimeZone.currentSystemDefault())} here")
}

実行します。

$ ./amper run
00:03.775 INFO  :example:compileJvm       Compiling module 'example' for platform 'jvm'...
Hello, World!
It's 2025-12-23T11:44:55.243773300 here
00:06.837 INFO  :example:runJvm           Process exited with exit code 0

テスト時の依存関係は test-dependencies で指定します。

settings で kotlin や jvm のバージョンを指定することができます。

まとめると以下のようになります。

product: jvm/app

dependencies:
  - org.jetbrains.kotlinx:kotlinx-datetime:0.6.2

test-dependencies:
  - io.mockk:mockk:1.13.10

settings:
  kotlin:
    version: 2.2.21
  jvm:
    release: 25

依存関係にはスコープを定義できます(デフォルトは all)。

Scope Compilation Runtime
all (default)
compile-only ×
runtime-only ×

以下のように指定します。

dependencies:
  - io.ktor:ktor-client-core:2.2.0: compile-only  
  - ../ui/utils: runtime-only


マルチモジュールプロジェクト

Amper の設定ファイルには project.yamlmodule.yaml があります。

単一モジュールの場合は module.yaml のみが必要です。

マルチモジュールプロジェクトの場合は project.yamlmodule.yaml を使い、以下のような構成を取ります。

├─ app/
│  ├─ src/
│  │  ├─ main.kt
│  │  └─ ...
│  └─ module.yaml
├─ libs/ 
│  ├─ lib1/
│  │  ├─ src/
│  │  │  └─ myLib1.kt
│  │  └─ module.yaml
│  └─ lib2/
│     ├─ src/
│     │  └─ myLib2.kt
│     └─ module.yaml
└─ project.yaml

project.yaml では以下のようにモジュールを構成します。

modules:
  - ./app
  - ./libs/lib1 
  - ./libs/lib2

app/module.yaml では、以下のようにモジュールの依存を定義します。

product: jvm/app

dependencies:
  - ./libs/lib1
  - ./libs/lib2






以上の内容はhttps://blog1.mammb.com/entry/2026/01/01/000000より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14