-
Notifications
You must be signed in to change notification settings - Fork 20
/
build.gradle.kts
223 lines (192 loc) · 5.72 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
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.jvm.toolchain.JavaLanguageVersion
import java.time.Instant
import java.time.ZoneId
import java.time.format.DateTimeFormatter
plugins {
`java-library`
application
`maven-publish`
signing
id("com.github.ben-manes.versions") version "0.51.0"
}
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"
tasks.withType<JavaCompile>().configureEach {
options.encoding = "UTF-8"
}
tasks.withType<Javadoc>().configureEach {
options.encoding = "UTF-8"
}
application {
mainModule.set("io.calimero.tools")
mainClass.set(System.getProperty("mainClass") ?: "io.calimero.tools.Main")
}
tasks.named<JavaExec>("run") {
standardInput = System.`in`
}
sourceSets {
main {
java.srcDirs("src")
resources.srcDir("resources")
}
test {
java.srcDirs("test")
}
create("serial")
create("usb")
}
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
withSourcesJar()
withJavadocJar()
registerFeature("serial") {
usingSourceSet(sourceSets["serial"])
}
registerFeature("usb") {
usingSourceSet(sourceSets["usb"])
}
}
tasks.withType<Jar>().configureEach {
from("$projectDir") {
include("LICENSE.txt")
into("META-INF")
}
if (name == "sourcesJar") {
from("$projectDir") {
include("README.md")
}
}
}
tasks.withType<JavaCompile>().configureEach {
options.compilerArgs.addAll(listOf(
"-Xlint:all",
"-Xlint:-try",
"-Xlint:-options",
"--add-reads", "io.calimero.tools=ALL-UNNAMED"
))
}
tasks.named<JavaCompile>("compileJava") {
options.javaModuleVersion = project.version.toString()
}
tasks.named<JavaCompile>("compileTestJava") {
options.compilerArgs.addAll(listOf(
"-Xlint:all",
"-Xlint:-try"
))
}
tasks.withType<Javadoc>().configureEach {
(options as CoreJavadocOptions).addStringOption("Xdoclint:-missing", "-quiet")
(options as CoreJavadocOptions).addStringOption("-add-reads", "io.calimero.tools=ALL-UNNAMED") // zip4j
}
val addReads = listOf(
"--add-reads", "io.calimero.tools=ALL-UNNAMED", // zip4j
"--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.withType<JavaExec>().configureEach {
jvmArgs(addReads)
// add as root module because it is required by non-modularized usb4java
jvmArgs("--add-modules", "org.apache.commons.lang3")
}
tasks.startScripts {
defaultJvmOpts = addReads
val rtClasspath = configurations.runtimeClasspath.get().files
val unixScriptFile = unixScript
val winScriptFile = windowsScript
doLast {
fun File.replace(replace: String, with: String) = writeText(readText().replace(replace, with))
// put commons-lang jar also on the classpath, used by libusb4java (which is in UNNAMED module)
val commonsLang3 = rtClasspath.filter { it.name.startsWith("commons-lang3") }
val libName = commonsLang3.first().name
unixScriptFile.replace("\n\nMODULE_PATH=", ":${'$'}APP_HOME/lib/$libName\n\nMODULE_PATH=")
winScriptFile.replace("\r\nset MODULE_PATH=", ";%APP_HOME%\\lib\\$libName\r\nset MODULE_PATH=")
}
}
dependencies {
api("io.calimero:calimero-core:$version")
implementation("net.lingala.zip4j:zip4j:2.11.5")
add("serialRuntimeOnly", "io.calimero:calimero-rxtx:$version")
add("serialRuntimeOnly", "io.calimero:serial-native:$version")
add("usbRuntimeOnly", "io.calimero:calimero-usb:$version")
runtimeOnly(sourceSets["serial"].runtimeClasspath)
runtimeOnly(sourceSets["usb"].runtimeClasspath)
runtimeOnly("org.slf4j:slf4j-jdk-platform-logging:2.0.12")
runtimeOnly("org.slf4j:slf4j-simple:2.0.12")
}
tasks.named<Jar>("jar") {
manifest {
val gitHash = providers.exec {
commandLine("git", "-C", "$projectDir", "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().files.joinToString(" ") { it.name }
)
}
}
tasks.distTar {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
tasks.distZip {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
publishing {
publications {
create<MavenPublication>("mavenJava") {
artifactId = rootProject.name
from(components["java"])
pom {
name.set("Calimero Tools")
description.set("A collection of tools for KNX network communication")
url.set("https://github.com/calimero-project/calimero-tools")
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-tools.git")
url.set("https://github.com/calimero-project/calimero-tools.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"])
}
}