Jetpack Compose for Desktop 开发注意

2022-11-17  本文已影响0人  雁过留声_泪落无痕

一、背景

二、build.gradle.kts

kotlin {
    jvm {
        compilations.all {
            kotlinOptions.jvmTarget = "11"
        }
        withJava()
    }
    sourceSets {
        val jvmMain by getting {
            dependencies {
                implementation(compose.desktop.currentOs)
                // implementation("com.google.code.gson:gson:2.8.5")
                implementation("com.squareup.retrofit2:retrofit:2.6.0")
                implementation("com.squareup.retrofit2:converter-gson:2.6.0")
            }
        }
        val jvmTest by getting
    }
}
// 避免每次 clean 后都需要再次下载, 这里直接在根目录放置下载好的文件, 用 task 进行拷贝
task("copyWix311", Copy::class) {
    from("wix311.zip")
    into("build/wixToolset")
}

// 需要在 afterEvaluate 中处理, 否则报找不到 packageMsi 这个 task 的错误
afterEvaluate {
    tasks.getByName("packageMsi").dependsOn("copyWix311")
    tasks.getByName("downloadWix").enabled = false

    if (file("build/wixToolset/unpacked").exists()) {
        tasks.getByName("unzipWix").enabled = false
    }
}
compose.desktop {
    application {
        mainClass = "com.xxx.MainKt"
        nativeDistributions {
            targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb, TargetFormat.Exe)
            packageName = "Xxx"
            packageVersion = "1.0.0"

            modules("java.sql")
        }
    }
}
通过阅读源码发现可以添加模块
compose.desktop {
    application {
        ...
        nativeDistributions {
            ...
            windows {
                iconFile.set(file("WIFI.ico"))
            }
        }
    }
}

示例

安装后运行截图

问题

上一篇 下一篇

猜你喜欢

热点阅读