-
Notifications
You must be signed in to change notification settings - Fork 8
/
build.gradle.kts
365 lines (335 loc) · 13.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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
import com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep
import com.github.vlsi.gradle.crlf.CrLfSpec
import com.github.vlsi.gradle.crlf.LineEndings
import com.github.vlsi.gradle.properties.dsl.props
import com.github.vlsi.gradle.properties.dsl.stringProperty
import com.github.vlsi.gradle.properties.dsl.toBool
import com.github.vlsi.gradle.publishing.dsl.simplifyXml
import com.github.vlsi.gradle.publishing.dsl.versionFromResolution
import net.ltgt.gradle.errorprone.errorprone
plugins {
idea
id("org.sonarqube")
id("com.diffplug.spotless")
id("com.github.vlsi.crlf")
id("com.github.vlsi.gradle-extensions")
id("com.github.vlsi.stage-vote-release")
id("net.ltgt.errorprone") apply false
}
val skipJavadoc by props()
val enableMavenLocal by props(false)
val enableGradleMetadata by props()
val enableErrorProne by props()
val skipSpotless by props(false)
val isRelease = project.stringProperty("release").toBool()
val snapshotName by props("")
if (isRelease && !JavaVersion.current().isJava9Compatible) {
throw GradleException("Java 9 compatible compiler is needed for release builds")
}
val String.v: String get() = rootProject.extra["$this.version"] as String
val projectVersion = "jsvg".v
val snapshotIdentifier = if (!isRelease && snapshotName.isNotEmpty()) "-$snapshotName" else ""
releaseParams {
tlp.set("jsvg")
organizationName.set("weisJ")
componentName.set("jsvg")
prefixForProperties.set("gh")
svnDistEnabled.set(false)
sitePreviewEnabled.set(false)
release.set(isRelease)
if (!isRelease) {
rcTag.set("v$projectVersion$snapshotIdentifier$snapshotSuffix")
}
nexus {
mavenCentral()
}
voteText.set {
"""
${it.componentName} v${it.version}-rc${it.rc} is ready for preview.
Git SHA: ${it.gitSha}
Staging repository: ${it.nexusRepositoryUri}
""".trimIndent()
}
}
tasks.closeRepository.configure { enabled = isRelease }
val buildVersion = "$projectVersion$snapshotIdentifier${releaseParams.snapshotSuffix}"
println("Building: JSVG $buildVersion")
println(" JDK: " + System.getProperty("java.home"))
println(" Gradle: " + gradle.gradleVersion)
sonarqube {
properties {
properties["sonar.issue.ignore.multicriteria"] = "e1"
// Disable checking of constants names: We follow the nomenclature of the standard which
// results in enums being camel case instead of upper snake case
properties["sonar.issue.ignore.multicriteria.e1.ruleKey"] = "java:S115"
properties["sonar.issue.ignore.multicriteria.e1.resourceKey"] = "**/*.java"
}
}
allprojects {
group = "com.github.weisj"
version = buildVersion
repositories {
if (enableMavenLocal) {
mavenLocal()
}
if (!isRelease) {
maven { url = uri("https://oss.sonatype.org/content/repositories/snapshots/") }
}
mavenCentral()
}
configurations.all {
resolutionStrategy.cacheChangingModulesFor(0, "seconds")
}
if (!skipSpotless) {
apply(plugin = "com.diffplug.spotless")
spotless {
val spotlessRatchet by props(default = true)
if (spotlessRatchet) {
ratchetFrom("origin/master")
}
kotlinGradle {
ktlint("ktlint".v)
}
format("markdown") {
target("**/*.md")
endWithNewline()
trimTrailingWhitespace()
}
format("svg") {
target("**/*.svg")
targetExclude("**/brokenUpCharContent.svg")
eclipseWtp(EclipseWtpFormatterStep.XML)
}
plugins.withType<JavaPlugin>().configureEach {
java {
importOrder("java", "javax", "org", "com")
removeUnusedImports()
eclipse().configFile("${project.rootDir}/config/java.eclipseformat.xml")
licenseHeaderFile("${project.rootDir}/config/LICENSE_HEADER.txt")
}
}
}
}
plugins.withType<JacocoPlugin> {
the<JacocoPluginExtension>().toolVersion = "jacoco".v
tasks.withType<JacocoReport>().configureEach {
reports {
xml.required.set(true)
html.required.set(true)
}
}
}
tasks.withType<AbstractArchiveTask>().configureEach {
// Ensure builds are reproducible
isPreserveFileTimestamps = false
isReproducibleFileOrder = true
dirPermissions {
user {
read = true
write = true
execute = true
}
group {
read = true
write = true
execute = true
}
other {
read = true
write = false
execute = true
}
}
filePermissions {
user {
read = true
write = true
execute = false
}
group {
read = true
write = false
execute = false
}
other {
read = true
write = false
execute = false
}
}
}
if (!enableGradleMetadata) {
tasks.withType<GenerateModuleMetadata> {
enabled = false
}
}
plugins.withType<JavaPlugin> {
configure<JavaPluginExtension> {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
withSourcesJar()
if (!skipJavadoc && isRelease) {
withJavadocJar()
}
}
apply(plugin = "maven-publish")
val useInMemoryKey by props()
if (useInMemoryKey) {
apply(plugin = "signing")
configure<SigningExtension> {
useInMemoryPgpKeys(
project.stringProperty("signing.inMemoryKey")?.replace("#", "\n"),
project.stringProperty("signing.password"),
)
}
}
if (enableErrorProne) {
apply(plugin = "net.ltgt.errorprone")
dependencies {
"errorprone"(toolLibs.errorprone.core)
"annotationProcessor"(toolLibs.errorprone.guava)
if (!JavaVersion.current().isJava9Compatible) {
"errorproneJavac"(toolLibs.errorprone.javac)
}
}
tasks.withType<JavaCompile>().configureEach {
options.compilerArgs.addAll(listOf("-Xmaxerrs", "10000", "-Xmaxwarns", "10000"))
if (props.bool("Werror", false)) {
options.compilerArgs.add("-Werror")
}
options.errorprone {
errorproneArgs.add("-XepExcludedPaths:.*/javacc/.*")
disableWarningsInGeneratedCode.set(true)
disable(
"StringSplitter",
"InlineMeSuggester",
"MissingSummary",
)
}
}
}
tasks {
withType<JavaCompile>().configureEach {
options.encoding = "UTF-8"
}
withType<ProcessResources>().configureEach {
from(source) {
include("**/*.properties")
filteringCharset = "UTF-8"
duplicatesStrategy = DuplicatesStrategy.INCLUDE
// apply native2ascii conversion since Java 8 expects properties to have ascii symbols only
filter(org.apache.tools.ant.filters.EscapeUnicode::class)
}
}
withType<Jar>().configureEach {
manifest {
attributes["Bundle-License"] = "MIT"
attributes["Implementation-Title"] = project.name
attributes["Implementation-Version"] = project.version
attributes["Specification-Vendor"] = "JSVG"
attributes["Specification-Version"] = project.version
attributes["Specification-Title"] = "JSVG"
attributes["Implementation-Vendor"] = "JSVG"
attributes["Implementation-Vendor-Id"] = "com.github.weisj"
}
CrLfSpec(LineEndings.LF).run {
into("META-INF") {
filteringCharset = "UTF-8"
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
// This includes either project-specific license or a default one
if (file("$projectDir/LICENSE").exists()) {
textFrom("$projectDir/LICENSE")
} else {
textFrom("$rootDir/LICENSE")
}
}
}
}
withType<Javadoc>().configureEach {
(options as StandardJavadocDocletOptions).apply {
// -add-exports requires target 9
// The library is built with target=1.8, so add-exports
if (project.the<JavaPluginExtension>().targetCompatibility.isJava9Compatible) {
addStringOption("-add-exports", "java.desktop/sun.swing=ALL-UNNAMED")
addStringOption("-add-exports", "java.desktop/sun.awt=ALL-UNNAMED")
addStringOption("-add-exports", "java.desktop/com.sun.java.swing=ALL-UNNAMED")
addStringOption("-add-exports", "java.desktop/sun.awt.shell=ALL-UNNAMED")
}
quiet()
locale = "en"
docEncoding = "UTF-8"
charSet = "UTF-8"
encoding = "UTF-8"
docTitle = "JSVG ${project.name} API"
windowTitle = "JSVG ${project.name} API"
header = "<b>JSVG</b>"
addBooleanOption("Xdoclint:none", true)
addStringOption("source", "8")
if (JavaVersion.current().isJava9Compatible) {
addBooleanOption("html5", true)
links("https://docs.oracle.com/javase/9/docs/api/")
} else {
links("https://docs.oracle.com/javase/8/docs/api/")
}
}
}
}
configure<PublishingExtension> {
if (project.path == ":") {
// Skip the root project
return@configure
}
publications {
create<MavenPublication>(project.name) {
artifactId = "${project.name}$snapshotIdentifier"
version = buildVersion
description = project.description
from(project.components["java"])
}
withType<MavenPublication> {
// Use the resolved versions in pom.xml
// Gradle might have different resolution rules, so we set the versions
// that were used in Gradle build/test.
versionFromResolution()
pom {
simplifyXml()
description.set(
project.description
?: "A lightweight Java2D SVG renderer",
)
name.set(
(project.findProperty("artifact.name") as? String)
?: project.name.replaceFirstChar { it.uppercase() }.replace("-", " "),
)
url.set("https://github.com/weisJ/jsvg")
organization {
name.set("com.github.weisj")
url.set("https://github.com/weisj")
}
issueManagement {
system.set("GitHub")
url.set("https://github.com/weisJ/jsvg/issues")
}
licenses {
license {
name.set("MIT")
url.set("https://github.com/weisj/jsvg/blob/master/LICENSE")
distribution.set("repo")
}
}
scm {
url.set("https://github.com/weisJ/jsvg")
connection.set("scm:git:git://github.com/weisJ/jsvg.git")
developerConnection.set("scm:git:ssh://[email protected]:weisj/jsvg.git")
}
developers {
developer {
name.set("Jannis Weis")
}
}
}
}
}
}
}
}