-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathbuild.gradle.kts
247 lines (216 loc) · 6.1 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
import java.text.SimpleDateFormat
import java.time.Instant
import java.time.ZoneId
import java.time.format.DateTimeFormatter
import java.util.Date
import java.util.Locale
plugins {
java
application
`maven-publish`
signing
id("com.github.ben-manes.versions") version "0.52.0"
eclipse
}
repositories {
mavenLocal()
mavenCentral()
maven("https://oss.sonatype.org/content/repositories/snapshots")
maven("https://s01.oss.sonatype.org/content/repositories/snapshots")
}
group = "io.calimero"
version = "3.0-SNAPSHOT"
fun date(): String = SimpleDateFormat("yyyyMMdd").format(Date())
val buildClassifier = date()
tasks.named<Zip>("distZip") {
archiveClassifier.set(buildClassifier)
}
tasks.named<Tar>("distTar") {
archiveClassifier.set(buildClassifier)
}
tasks.withType<JavaCompile>().configureEach {
options.encoding = "UTF-8"
}
tasks.withType<Javadoc>().configureEach {
options.encoding = "UTF-8"
}
application {
mainModule.set("io.calimero.gui")
mainClass.set("io.calimero.gui.SwtChecker")
}
// SWT is platform dependent
val swtGroupId = "org.eclipse.platform"
val swtVersion = "3.128.0"
var swtArtifact = "org.eclipse.swt."
val os = System.getProperty("os.name").lowercase(Locale.ENGLISH)
swtArtifact += when {
os.contains("windows") -> "win32.win32."
os.contains("linux") -> "gtk.linux."
os.contains("mac") -> "cocoa.macosx."
else -> ""
}
val arch = System.getProperty("os.arch")
swtArtifact += when (arch) {
"aarch64" -> "aarch64"
"amd64", "x86_64" -> "x86_64"
else -> "x86"
}
sourceSets {
main {
java.srcDirs("src")
resources.srcDir("resources")
}
}
tasks.withType<JavaCompile>().configureEach {
options.compilerArgs = listOf(
"-Xlint:all",
"--add-reads", "io.calimero.gui=ALL-UNNAMED" // usb4java-javax
)
}
tasks.named<JavaCompile>("compileJava") {
options.javaModuleVersion = version.toString()
}
configurations {
create("provided")
configurations.compileOnly.get().extendsFrom(configurations["provided"])
}
configurations.all {
resolutionStrategy.dependencySubstitution {
substitute(module("org.eclipse.platform:org.eclipse.swt.\${osgi.platform}"))
.using(module("$swtGroupId:$swtArtifact:$swtVersion"))
}
}
dependencies {
implementation("io.calimero:calimero-core:$version")
implementation("io.calimero:calimero-tools:$version")
runtimeOnly("io.calimero:calimero-tools:$version") {
capabilities {
requireCapability("io.calimero:calimero-tools-serial")
}
}
runtimeOnly("io.calimero:calimero-tools:$version") {
capabilities {
requireCapability("io.calimero:calimero-tools-usb")
}
}
implementation("$swtGroupId:$swtArtifact:$swtVersion")
}
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
withSourcesJar()
}
tasks.withType<Jar>().configureEach {
from(project.projectDir) {
include("LICENSE.txt")
into("META-INF")
}
if (name == "sourcesJar") {
from(project.projectDir) {
include("README.md")
}
}
}
tasks.named<Jar>("jar") {
dependsOn(configurations.runtimeClasspath)
manifest {
val gitHash = providers.exec {
commandLine("git", "-C", project.projectDir.toString(), "rev-parse", "--verify", "--short", "HEAD")
}.standardOutput.asText.map { it.trim() }
val buildDate = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss z")
.withZone(ZoneId.of("UTC"))
.format(Instant.now())
attributes(
"Main-Class" to application.mainClass.get(),
"Implementation-Version" to project.version,
"Revision" to gitHash.get(),
"Build-Date" to buildDate,
"Class-Path" to (configurations.runtimeClasspath.get() - configurations["provided"] + files("swt.jar")).map { it.name }.joinToString(" ")
)
}
}
application {
applicationDistribution.from(project.projectDir) {
include("LICENSE.txt")
}
}
distributions {
main {
contents {
exclude(configurations["provided"].map { it.name })
}
}
}
val addReads = listOf(
"--add-reads", "io.calimero.core=io.calimero.tools", // @LinkEvent
"--add-reads", "io.calimero.serial.provider.rxtx=ALL-UNNAMED",
"--add-reads", "io.calimero.usb.provider.javax=ALL-UNNAMED"
)
tasks.startScripts {
defaultJvmOpts = addReads
doLast {
fun File.replace(replace: String, with: String) = writeText(readText().replace(replace, with))
// on OS X, SWT needs to run on first thread
unixScript.replace("DEFAULT_JVM_OPTS='",
"""
MACOS_JVM_OPTS=""
if [ "`uname`" = Darwin ] ; then
MACOS_JVM_OPTS="-XstartOnFirstThread"
fi
DEFAULT_JVM_OPTS="${'$'}{MACOS_JVM_OPTS}"' """.trimIndent())
// add dependency on downloaded swt.jar (adding files('swt.jar') to classpath doesn't work)
unixScript.replace("MODULE_PATH=\$APP_HOME", "MODULE_PATH=\$APP_HOME/lib/swt.jar:\$APP_HOME")
windowsScript.replace("MODULE_PATH=%APP_HOME%", "MODULE_PATH=%APP_HOME%\\lib\\swt.jar;%APP_HOME%")
}
}
tasks.withType<JavaExec>().configureEach {
jvmArgs(addReads)
if (os.contains("mac")) {
jvmArgs("-XstartOnFirstThread")
}
}
publishing {
publications {
create<MavenPublication>("mavenJava") {
artifactId = rootProject.name
from(components["java"])
pom {
name.set("Calimero GUI")
description.set("A graphical user interface for the Calimero tools collection")
url.set("https://github.com/calimero-project/calimero-gui")
inceptionYear.set("2006")
licenses {
license {
name.set("GNU General Public License, version 2, with the Classpath Exception")
url.set("LICENSE.txt")
}
}
developers {
developer {
name.set("Boris Malinowsky")
email.set("[email protected]")
}
}
scm {
connection.set("scm:git:git://github.com/calimero-project/calimero-gui.git")
url.set("https://github.com/calimero-project/calimero-gui.git")
}
}
}
}
repositories {
maven {
name = "maven"
val releasesRepoUrl = uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2")
val snapshotsRepoUrl = uri("https://s01.oss.sonatype.org/content/repositories/snapshots")
url = if (version.toString().endsWith("SNAPSHOT")) snapshotsRepoUrl else releasesRepoUrl
credentials(PasswordCredentials::class)
}
}
}
signing {
if (project.hasProperty("signing.keyId")) {
sign(publishing.publications["mavenJava"])
}
}