シフトの日記

趣味のゲームやプログラムについてまったり書いていきます

Jetpack Compose for Desktop は依存関係の解決をOS毎に自動で処理している

IDEAのテンプレートからCompose のデスクトップアプリの雛形を生成したらgradleファイルに下記の記述を見つけました

dependencies {
    testImplementation(kotlin("test"))
    implementation(compose.desktop.currentOs)
}

文字列の指定ではなく currentOs って指定だったので気になったので処理を追ってみました

val currentOs by lazy {
  composeDependency("org.jetbrains.compose.desktop:desktop-jvm-${currentTarget.id}")
}

こんな感じで currentTarget からIDを取得していて、 currentTargetの中で currentOS っていう変数に実行環境のOSを設定していました

internal val currentOS: OS by lazy {
    val os = System.getProperty("os.name")
    when {
        os.equals("Mac OS X", ignoreCase = true) -> OS.MacOS
        os.startsWith("Win", ignoreCase = true) -> OS.Windows
        os.startsWith("Linux", ignoreCase = true) -> OS.Linux
        else -> error("Unknown OS name: $os")
    }
}

System.getProperty("os.name") って取れる値ってそのまま Win とかなんですね