-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild.gradle.kts
executable file
·252 lines (222 loc) · 9.11 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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
/*
* Copyright (c) 2021 Toast Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version "2.0.21"
id("org.jetbrains.compose") version "1.6.11"
id("org.jetbrains.kotlin.plugin.compose") version "2.0.21"
id("org.jlleitschuh.gradle.ktlint") version "11.3.2"
}
val appVersion = "1.4.1"
group = "com.toasttab.pulseman"
version = appVersion
repositories {
mavenCentral()
maven { url = uri("https://maven.google.com") }
}
val assertJVersion: String by rootProject
val composeVersion: String by rootProject
val googleCommonProtos: String by rootProject
val jacksonVersion: String by rootProject
val jUnitVersion: String by rootProject
val kotlinVersion: String by rootProject
val mockkVersion: String by rootProject
val protobufUtils: String by rootProject
val protoktVersion: String by rootProject
val pulsarVersion: String by rootProject
val reflectionsVersion: String by rootProject
val rsyntaxVersion: String by rootProject
val sl4jNoop: String by rootProject
val testContainerPulsar: String by rootProject
configurations {
compileOnly {
isCanBeResolved = true
}
}
val tempBuildDir = "$buildDir/temp/"
val pulsarClientJar = "pulsar-client-$pulsarVersion.jar"
dependencies {
implementation(compose.desktop.currentOs)
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jacksonVersion")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:$jacksonVersion")
implementation("com.fifesoft:rsyntaxtextarea:$rsyntaxVersion")
implementation("com.google.protobuf:protobuf-java:$protobufUtils")
implementation("com.google.protobuf:protobuf-java-util:$protobufUtils")
implementation("com.google.protobuf:protobuf-kotlin:$protobufUtils")
implementation("com.toasttab.protokt:protokt-core:$protoktVersion")
implementation("com.toasttab.protokt:protokt-extensions:$protoktVersion")
implementation("org.apache.pulsar:pulsar-client-admin:$pulsarVersion")
implementation("org.jetbrains.compose.material:material-icons-extended:$composeVersion")
implementation("org.jetbrains.kotlin:kotlin-compiler-embeddable:$kotlinVersion")
implementation("org.jetbrains.kotlin:kotlin-script-runtime:$kotlinVersion")
implementation("org.jetbrains.kotlin:kotlin-scripting-compiler-embeddable:$kotlinVersion")
implementation("org.jetbrains.kotlin:kotlin-scripting-jsr223:$kotlinVersion")
implementation("org.jetbrains.kotlin:kotlin-scripting-jvm-host:$kotlinVersion")
implementation("org.jetbrains.kotlin:kotlin-scripting-jvm:$kotlinVersion")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion")
implementation("org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion")
implementation("org.reflections:reflections:$reflectionsVersion")
implementation("org.slf4j:slf4j-nop:$sl4jNoop")
/**
* The pulsar-client jar is causing an issue with signing Mac apps, something to do with
* the compressed size being mismatched.
* Cause: invalid entry compressed size (expected 5232 but got 5227 bytes)
* Stripping all META-INF from the import via gradle task for now to make it work.
* This happened with multiple versions of the import.
*
* STRIP META-INF Part 1: Download the jar but don't include it in the final app.
*/
compileOnly("org.apache.pulsar:pulsar-client:$pulsarVersion")
/**
* The protokt version of proto-google-common-protos uses the same package and class names.
* They are only being downloaded and packaged with the release they will not be automatically loaded into the
* classloader.
* They will be added to separate classloaders one for protoKT protos and one for standard protos.
*/
compileOnly("com.google.api.grpc:proto-google-common-protos:$googleCommonProtos")
compileOnly("com.toasttab.protokt.thirdparty:proto-google-common-protos:$protoktVersion")
testImplementation("io.mockk:mockk:$mockkVersion")
testImplementation("org.apache.pulsar:pulsar-client-admin-original:$pulsarVersion")
testImplementation("org.assertj:assertj-core:$assertJVersion")
testImplementation("org.junit.jupiter:junit-jupiter:$jUnitVersion")
testImplementation("org.junit.jupiter:junit-jupiter-params:$jUnitVersion")
testImplementation("org.testcontainers:pulsar:$testContainerPulsar")
}
tasks {
test {
exclude("**/*IT*.class")
useJUnitPlatform()
}
}
task<Test>("iTest") {
group = "verification"
useJUnitPlatform()
}
ktlint {
verbose.set(true)
outputToConsole.set(true)
}
tasks.withType<KotlinCompile> {
compilerOptions {
jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17)
allWarningsAsErrors.set(true)
}
}
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}
kotlin.sourceSets.all {
languageSettings.optIn("kotlin.RequiresOptIn")
}
/**
* This will copy and rename the downloaded common protos to the resource folder, so they can be loaded to custom
* Jar Loaders at runtime
*/
val copyCommonProtoJarToResources by tasks.creating(Copy::class) {
// Files have to be in the common folder to be included with the release package for all OS variations, e.g. Mac/Windows/Linux
into("src/main/resources/common")
val filteredFiles = configurations.compileOnly
.get()
.filter { it.name.startsWith("proto-google-common-protos") }
from(filteredFiles)
filteredFiles.forEach { file ->
val originalFileName = file.name
val newFileName = if (originalFileName.endsWith("$googleCommonProtos.jar")) {
originalFileName.replace(googleCommonProtos, "original")
} else {
originalFileName.replace(protoktVersion, "protoKT")
}
rename(originalFileName, newFileName)
}
}
/**
* STRIP META-INF Part 2: Copy the jar to a temp directory
*/
val copyPulsarClientTask by tasks.creating(Copy::class) {
into("$buildDir/temp")
from(configurations.compileOnly.get().find { it.name.equals(pulsarClientJar) })
}
/**
* STRIP META-INF Part 3: Strip the META-INF from the pulsar client jar.
*/
val stripMetaInfTask: TaskProvider<Task> = tasks.register("stripMetaInf") {
dependsOn(copyPulsarClientTask)
doLast {
val jarFile = file("$tempBuildDir$pulsarClientJar")
exec {
commandLine("zip", "-d", jarFile.absolutePath, "META-INF/*")
}
}
}
/**
* STRIP META-INF Part 4: Make the stripped jar an implementation dependency on the app.
*/
val importPulsarClientTask: TaskProvider<Task> = tasks.register("importPulsarClientTask") {
dependsOn(stripMetaInfTask)
doLast {
dependencies {
implementation(files("$tempBuildDir$pulsarClientJar"))
}
}
}
tasks.named("processResources") {
dependsOn(copyCommonProtoJarToResources)
}
/**
* STRIP META-INF Part 0: Kick off flow
*/
tasks.named("assemble") {
dependsOn(importPulsarClientTask)
}
/**
* Make sure package creation doesn't start until common proto jars copied, package creation fails without this dependency.
*/
gradle.projectsEvaluated {
tasks.named("prepareAppResources") {
dependsOn(copyCommonProtoJarToResources)
}
}
compose.desktop {
application {
mainClass = "com.toasttab.pulseman.MainKt"
nativeDistributions {
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
packageName = "Pulseman"
packageVersion = appVersion
description = "Send and receive messages with pulsar"
copyright = "Copyright (c) 2021 Toast Inc"
includeAllModules = true
macOS {
iconFile.set(project.file("pulse.icns"))
bundleID = "com.tempaccount.pulseman"
signing {
sign.set(System.getenv("SIGN_APP")?.toString()?.toBoolean() ?: false)
identity.set(System.getenv("IDENTITY_TEMP") ?: "")
}
notarization {
appleID.set(System.getenv("APPLE_ID_TEMP") ?: "")
password.set(System.getenv("NOTARIZATION_PASSWORD_TEMP") ?: "")
teamID.set(System.getenv("PROVIDER_TEMP") ?: "")
}
}
// This sets the resource folder location and will include the folders contents in the packaged release
// https://github.com/JetBrains/compose-multiplatform/tree/master/tutorials/Native_distributions_and_local_execution#jvm-resource-loading
appResourcesRootDir.set(project.layout.projectDirectory.dir("src/main/resources"))
}
}
}