Skip to content

Commit aba4496

Browse files
committed
依赖升级
1 parent 0babec2 commit aba4496

28 files changed

+33
-165
lines changed

build.gradle.kts

+18-159
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,38 @@
1-
import org.jetbrains.compose.compose
21
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
3-
import java.nio.file.Files
42

53
plugins {
6-
kotlin("multiplatform")
7-
id("org.jetbrains.compose")
4+
alias(libs.plugins.kotlinMultiplatform)
5+
alias(libs.plugins.composeCompiler)
6+
alias(libs.plugins.composeMultiplatform)
7+
alias(libs.plugins.buildconfig)
88
}
99

1010
group = "top.ntutn"
1111
version = "2.0.0"
1212

13+
buildConfig {
14+
buildConfigField("String", "APP_NAME", "\"${project.name}\"")
15+
buildConfigField("String", "APP_VERSION", "\"${version}\"")
16+
}
17+
1318
repositories {
1419
google()
1520
mavenCentral()
1621
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
1722
}
1823

1924
kotlin {
20-
jvm {
21-
compilations.all {
22-
kotlinOptions.jvmTarget = "11"
23-
}
24-
withJava()
25-
}
25+
jvm("desktop")
2626
sourceSets {
27-
val jvmMain by getting {
28-
kotlin {
29-
sourceSets["jvmMain"].kotlin.srcDir("build/src/generated/kotlin")
30-
}
31-
dependencies {
32-
implementation(compose.desktop.currentOs)
33-
// https://mvnrepository.com/artifact/org.apache.commons/commons-lang3
34-
implementation("org.apache.commons:commons-lang3:3.12.0")
35-
// https://mvnrepository.com/artifact/com.arkivanov.decompose/decompose
36-
// implementation("com.arkivanov.decompose:decompose:1.0.0-alpha-06")
37-
// implementation("com.arkivanov.decompose:extensions-compose-jetbrains:1.0.0-alpha-06")
38-
implementation("org.mapdb:mapdb:3.0.8") {
39-
exclude("org.jetbrains.kotlin", "kotlin-stdlib")
40-
}
27+
val desktopMain by getting
28+
desktopMain.dependencies {
29+
implementation(compose.desktop.currentOs)
30+
implementation("org.apache.commons:commons-lang3:3.12.0")
31+
implementation("org.mapdb:mapdb:3.0.8") {
32+
exclude("org.jetbrains.kotlin", "kotlin-stdlib")
4133
}
34+
implementation(libs.kotlinx.coroutines.swing)
4235
}
43-
val jvmTest by getting
4436
}
4537
}
4638

@@ -53,7 +45,7 @@ compose.desktop {
5345
packageName = "floatclock"
5446
packageVersion = version.toString()
5547
linux {
56-
iconFile.set(project.file("src/jvmMain/resources/clock.png"))
48+
iconFile.set(project.file("src/desktopMain/resources/clock.png"))
5749
}
5850
windows {
5951
shortcut = true
@@ -63,139 +55,6 @@ compose.desktop {
6355
}
6456
}
6557
args("--release")
66-
// https://stackoverflow.com/a/44059335
67-
/**
68-
* Exception in thread "AWT-EventQueue-0" java.lang.reflect.InaccessibleObjectException: Unable to make private static int javax.swing.JOptionPane.styleFromMessageType(int) accessible: module java.desktop does not "opens javax.swing" to unnamed module @6e428587
69-
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
70-
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
71-
at java.base/java.lang.reflect.Method.checkCanSetAccessible(Method.java:199)
72-
at java.base/java.lang.reflect.Method.setAccessible(Method.java:193)
73-
at top.ntutn.zhd.util.MsgBox$Companion.showOptionDialog(MsgBox.kt:29)
74-
at top.ntutn.zhd.util.MsgBox$Companion.access$showOptionDialog(MsgBox.kt:11)
75-
at top.ntutn.zhd.util.MsgBox.show(MsgBox.kt:100)
76-
at top.ntutn.zhd.httrack.HttrackComponent$startListen$2.invokeSuspend(HttrackComponent.kt:51)
77-
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
78-
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
79-
at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:318)
80-
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:771)
81-
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:722)
82-
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:716)
83-
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
84-
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
85-
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:741)
86-
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
87-
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
88-
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
89-
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
90-
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
91-
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
92-
Suppressed: kotlinx.coroutines.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@511348e2, Dispatchers.Main]
93-
*/
9458
jvmArgs += listOf("--add-opens=java.desktop/javax.swing=ALL-UNNAMED")
9559
}
9660
}
97-
98-
tasks.register("generateBuildConfig") {
99-
val content = """
100-
package top.ntutn.floatclock
101-
102-
object BuildConfig {
103-
val version = "$version"
104-
}
105-
""".trimIndent()
106-
val dir = File(projectDir, "build/src/generated/kotlin/top/ntutn/floatclock").also {
107-
if (it.exists()) {
108-
it.deleteRecursively()
109-
}
110-
it.mkdirs()
111-
}
112-
File(dir, "BuildConfig.kt").writeText(content)
113-
}
114-
115-
tasks.register("repackageDeb") {
116-
dependsOn(tasks.getByPath("packageDeb"))
117-
doLast {
118-
val repackageOutputPath = File(projectDir, "build/compose/binaries/main/repackageDeb")
119-
if (repackageOutputPath.exists()) {
120-
repackageOutputPath.deleteRecursively()
121-
}
122-
repackageOutputPath.mkdirs()
123-
println("repackage output is ${repackageOutputPath.absolutePath}")
124-
val extractPath = File(repackageOutputPath, "extract").also { it.mkdir() }
125-
val debianPath = File(extractPath, "DEBIAN").also { it.mkdir() }
126-
val buildPath = File(repackageOutputPath, "build").also { it.mkdir() }
127-
128-
// 查找原有deb文件
129-
val originDebFile = File(projectDir, "build/compose/binaries/main/deb").listFiles { _: File, name: String ->
130-
name.endsWith(".deb")
131-
}?.firstOrNull()
132-
require(originDebFile != null) { "未找到原始打包结果!" }
133-
134-
println("原始打包结果 ${originDebFile.absolutePath}")
135-
136-
// 解包
137-
execProcessWait("dpkg", "-X", originDebFile.absolutePath, extractPath.absolutePath + "/")
138-
execProcessWait("dpkg", "-e", originDebFile.absolutePath, debianPath.absolutePath + "/")
139-
140-
// 释放LICENSE文件
141-
File(debianPath, "copyright").writeText(File(projectDir, "LICENSE").readText())
142-
File(extractPath, "opt/floatclock/share/doc/copyright").writeText(File(projectDir, "LICENSE").readText())
143-
144-
// 重建快捷方式
145-
val libDir = File(extractPath, "opt/floatclock/lib")
146-
File(projectDir, "repackageDeb/opt/floatclock/lib/floatclock.desktop").copyTo(File(libDir, "floatclock-floatclock.desktop"), true)
147-
148-
// 覆盖控制脚本
149-
val installSize = Files.walk(File(extractPath, "opt").toPath()).mapToLong { p -> p.toFile().length() }.sum().let {
150-
(it / 1024f).toLong()
151-
}
152-
val newControl = File(projectDir, "repackageDeb/DEBIAN/control").readText()
153-
.replace("{version}", version.toString())
154-
.replace("{maintainer}", "zerofancy")
155-
.replace("{maintainer-email}", "[email protected]")
156-
.replace("{description}", "A simple clock floating on other windows.")
157-
.replace("{installed-size}", installSize.toString())
158-
.replace("{homepage}", "https://github.com/zerofancy/floatclock")
159-
File(debianPath, "control").writeText(newControl)
160-
File(projectDir, "repackageDeb/DEBIAN/preinst").copyTo(File(debianPath, "preinst"), true)
161-
162-
// 重置DEBIAN文件夹权限
163-
execProcessWait("chmod", "755", "-R", debianPath.absolutePath)
164-
165-
// 重新打包 (ubuntu下默认使用zstd压缩,但这不能被debian/deepin现有版本支持)
166-
execProcessWait("dpkg-deb", "-b","-Zxz", extractPath.absolutePath, buildPath.absolutePath + "/")
167-
168-
val outputFile = buildPath.listFiles { _: File, name: String-> name.endsWith(".deb") }?.firstOrNull()
169-
require(outputFile != null)
170-
171-
val arch = "amd64"
172-
val finalOutputFile = File(buildPath, "floatclock_${version}-1_$arch.deb")
173-
174-
outputFile.renameTo(finalOutputFile)
175-
176-
println("重新打包输出文件 ${finalOutputFile.absolutePath}")
177-
}
178-
}
179-
180-
fun execProcessWait(command: String, vararg args: String = emptyArray()) {
181-
val commandAndArgs = listOf(command) + args
182-
print("exec:" + commandAndArgs.joinToString(" "))
183-
val process = Runtime.getRuntime().exec(commandAndArgs.toTypedArray())
184-
val code = process.waitFor()
185-
process.inputStream.use { inputStream ->
186-
inputStream.readAllBytes().decodeToString().let {
187-
println(it)
188-
}
189-
}
190-
process.errorStream.use {
191-
val errorOutput = it.readAllBytes().decodeToString()
192-
println(errorOutput)
193-
}
194-
require(code == 0)
195-
}
196-
197-
tasks {
198-
"compileJava" {
199-
dependsOn("generateBuildConfig")
200-
}
201-
}

gradle/libs.versions.toml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[versions]
2+
compose-multiplatform = "1.7.3"
3+
kotlin = "2.1.20"
4+
kotlinx-coroutines = "1.10.2"
5+
buildconfig = "5.6.2"
6+
7+
[libraries]
8+
kotlinx-coroutines-swing = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-swing", version.ref = "kotlinx-coroutines" }
9+
10+
[plugins]
11+
composeMultiplatform = { id = "org.jetbrains.compose", version.ref = "compose-multiplatform" }
12+
composeCompiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
13+
kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
14+
buildconfig = { id = "com.github.gmazzo.buildconfig", version.ref = "buildconfig" }

settings.gradle.kts

-5
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ pluginManagement {
66
mavenCentral()
77
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
88
}
9-
10-
plugins {
11-
kotlin("multiplatform").version(extra["kotlin.version"] as String)
12-
id("org.jetbrains.compose").version(extra["compose.version"] as String)
13-
}
149
}
1510

1611
rootProject.name = "floatclock"

src/jvmMain/kotlin/top/ntutn/floatclock/AboutDialog.kt renamed to src/desktopMain/kotlin/top/ntutn/floatclock/AboutDialog.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ fun AboutContent() {
3333
modifier = modifier.size(64.dp, 64.dp)
3434
)
3535
Spacer(modifier.height(8.dp))
36-
Text("kotlin-float-clock ${BuildConfig.version}", modifier = modifier)
36+
Text("${BuildConfig.APP_NAME} ${BuildConfig.APP_VERSION}", modifier = modifier)
3737
Spacer(modifier.height(8.dp))
3838
ClickableText(buildAnnotatedString {
3939
pushStringAnnotation(tag = "URL", annotation = url)
File renamed without changes.

0 commit comments

Comments
 (0)