-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
192 lines (164 loc) · 6.84 KB
/
build.gradle.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
import org.jetbrains.kotlin.com.google.gson.*
import java.io.ByteArrayOutputStream
import java.time.LocalDate
plugins {
kotlin("jvm")
id("org.jetbrains.compose")
kotlin("plugin.serialization") version "1.8.0"
}
group = "org.ibci"
version = "1.0.3"
repositories {
mavenCentral()
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
google()
}
dependencies {
// Note, if you develop a library, you should use compose.desktop.common.
// compose.desktop.currentOs should be used in launcher-sourceSet
// (in a separate module for demo project and in testMain).
// With compose.desktop.common you will also lose @Preview functionality
implementation(compose.desktop.currentOs)
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-swing:1.6.4")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.2")
implementation("org.jetbrains.kotlinx:kotlinx-cli:0.3.5")
implementation("net.java.dev.jna:jna:5.8.0")
implementation("net.java.dev.jna:jna-platform:5.8.0")
implementation("org.zeromq:jeromq:0.6.0")
}
compose.desktop {
application {
mainClass = "org.ibci.componentinstaller.main.MainKt"
nativeDistributions {
//targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
targetFormats(TargetFormat.Exe) // To build the actual exe file use the gradle task createDistributable!
packageName = "ComponentInstaller"
packageVersion = version.toString()
}
}
}
// Here are custom gradle tasks
val versionHistoryFile = file("src/main/resources/version_history.json")
/**
* Appends the latest version number to the version_history.json file
*/
tasks.register<DefaultTask>("appendVersion") {
description = "Appends current project version to versionHistory.json"
doLast {
val currentVersion = project.version.toString()
val releaseDate = LocalDate.now().toString()
val existingData = if (versionHistoryFile.exists()) {
// Read existing data if file exists, handle potential exceptions
try {
Gson().fromJson(versionHistoryFile.readText(), JsonObject::class.java)
} catch (e: Exception) {
logger.warn("Error reading existing version history: $e")
JsonObject()
}
} else {
JsonObject()
}
val versionHistory = existingData.getAsJsonArray("versionHistory") ?: JsonArray()
val newEntry = JsonObject().apply {
addProperty("version", currentVersion)
addProperty("releaseDate", releaseDate)
}
versionHistory.add(newEntry)
val tmpGson: Gson = GsonBuilder().setPrettyPrinting().create()
versionHistoryFile.writeText(tmpGson.toJson(existingData))
}
}
/**
* Substitutes the version number placeholder in the inno setup script with the latest one
*/
tasks.register("updateVersionInInnoSetupScriptOnline") {
dependsOn("appendVersion")
mustRunAfter("appendVersion")
doLast {
val template = file("$projectDir/deployment/inno_setup/base.iss").readText()
val processedScript = template.replace("{#AppVersion}", version.toString())
file("$projectDir/deployment/inno_setup/base_with_version.iss").writeText(processedScript)
}
}
/**
* Substitutes the version number placeholder in the inno setup script with the latest one
*/
tasks.register("updateVersionInInnoSetupScriptOffline") {
dependsOn("appendVersion")
mustRunAfter("appendVersion")
doLast {
val template = file("$projectDir/deployment/inno_setup/baseOffline.iss").readText()
val processedScript = template.replace("{#AppVersion}", version.toString())
file("$projectDir/deployment/inno_setup/base_offline_with_version.iss").writeText(processedScript)
}
}
tasks.register<Exec>("prepareInnoSetupScriptOnline") {
mustRunAfter("updateVersionInInnoSetupScriptOnline", "createDistributable", "publishWindowsCmdElevator")
val copyScript = file("$projectDir/deployment/inno_setup/copy_inno_src.bat")
commandLine("cmd", "/c", copyScript)
}
tasks.register<Exec>("prepareInnoSetupScriptOffline") {
mustRunAfter("updateVersionInInnoSetupScriptOffline", "createDistributable", "publishWindowsCmdElevator")
val copyScript = file("$projectDir/deployment/inno_setup/copy_inno_src_offline.bat")
commandLine("cmd", "/c", copyScript)
}
tasks.register<Exec>("compileOnlineInnoSetup") {
dependsOn(
"appendVersion",
"updateVersionInInnoSetupScriptOnline",
"createDistributable",
"publishWindowsCmdElevator",
"publishWindowsTasks",
"prepareInnoSetupScriptOnline"
)
mustRunAfter("prepareInnoSetupScriptOnline")
val innoSetupPath = "C:\\Program Files (x86)\\Inno Setup 6\\ISCC.exe"
val setupScript = file("$projectDir/deployment/inno_setup/base_with_version.iss")
commandLine(innoSetupPath, setupScript)
}
tasks.register<Exec>("compileOfflineInnoSetup") {
dependsOn(
"appendVersion",
"updateVersionInInnoSetupScriptOffline",
"createDistributable",
"publishWindowsCmdElevator",
"publishWindowsTasks",
"prepareInnoSetupScriptOffline"
)
mustRunAfter("prepareInnoSetupScriptOffline")
val innoSetupPath = "C:\\Program Files (x86)\\Inno Setup 6\\ISCC.exe"
val setupScript = file("$projectDir/deployment/inno_setup/base_offline_with_version.iss")
commandLine(innoSetupPath, setupScript)
}
tasks.register<Exec>("publishWindowsCmdElevator") {
// Define the command to publish the project
val pubxmlFile = file("$projectDir/WindowsWrapper/WindowsCmdElevator/Properties/PublishProfiles/FolderProfile.pubxml")
commandLine("dotnet", "publish", "$projectDir/WindowsWrapper/WindowsCmdElevator", "/p:PublishProfile=$pubxmlFile")
// Setting the working directory
workingDir = file(projectDir)
// Capture and log the output
val outputStream = ByteArrayOutputStream()
standardOutput = outputStream
errorOutput = outputStream
isIgnoreExitValue = true
doLast {
println(outputStream.toString())
}
}
tasks.register<Exec>("publishWindowsTasks") {
// Define the command to publish the project
val pubxmlFile = file("$projectDir/WindowsWrapper/WindowsTasks/Properties/PublishProfiles/FolderProfile.pubxml")
commandLine("dotnet", "publish", "$projectDir/WindowsWrapper/WindowsTasks", "/p:PublishProfile=$pubxmlFile")
// Setting the working directory
workingDir = file(projectDir)
// Capture and log the output
val outputStream = ByteArrayOutputStream()
standardOutput = outputStream
errorOutput = outputStream
isIgnoreExitValue = true
doLast {
println(outputStream.toString())
}
}