-
Notifications
You must be signed in to change notification settings - Fork 11
/
build.gradle.kts
540 lines (469 loc) · 21.2 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
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
import com.adarshr.gradle.testlogger.theme.ThemeType
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import io.freefair.gradle.plugins.lombok.LombokExtension
import org.ajoberstar.grgit.Grgit
import org.gradle.util.GradleVersion
import java.nio.file.Files
import java.nio.file.StandardCopyOption
import java.text.SimpleDateFormat
import java.util.Date
plugins {
java
signing
`maven-publish`
idea
if (org.gradle.util.GradleVersion.current() < org.gradle.util.GradleVersion.version("5.4")) {
id("com.diffplug.gradle.spotless") version "4.5.1"
} else {
id("com.diffplug.spotless") version "5.14.2"
}
id("com.gradle.plugin-publish") version "0.15.0"
id("net.linguica.maven-settings") version "0.5"
id("net.researchgate.release") version "2.8.1"
id("org.ajoberstar.grgit") version "4.1.1"
when {
org.gradle.util.GradleVersion.current() < org.gradle.util.GradleVersion.version("5.0") -> {
id("com.adarshr.test-logger") version "1.7.1"
// XXX: Versions 4.x > 4.0.1 suffer from <https://github.com/johnrengelman/shadow/issues/425>
id("com.github.johnrengelman.shadow") version "4.0.1"
}
org.gradle.util.GradleVersion.current() < org.gradle.util.GradleVersion.version("6.0") -> {
id("com.adarshr.test-logger") version "2.1.1"
id("com.github.johnrengelman.shadow") version "5.2.0"
}
org.gradle.util.GradleVersion.current() < org.gradle.util.GradleVersion.version("7.0") -> {
id("com.adarshr.test-logger") version "2.1.1"
id("com.github.johnrengelman.shadow") version "6.1.0"
}
org.gradle.util.GradleVersion.current() < org.gradle.util.GradleVersion.version("8.0") -> {
id("com.adarshr.test-logger") version "3.2.0"
id("com.github.johnrengelman.shadow") version "7.1.2"
}
else -> {
id("com.adarshr.test-logger") version "3.2.0"
id("com.github.johnrengelman.shadow") version "8.1.0"
}
}
when {
org.gradle.util.GradleVersion.current() < org.gradle.util.GradleVersion.version("5.0") -> {
id("io.freefair.lombok") version "2.9.5" apply false
}
org.gradle.util.GradleVersion.current() < org.gradle.util.GradleVersion.version("5.2") -> {
id("io.freefair.lombok") version "3.0.0" apply false
}
org.gradle.util.GradleVersion.current() < org.gradle.util.GradleVersion.version("6.0") -> {
id("io.freefair.lombok") version "4.1.6" apply false
}
org.gradle.util.GradleVersion.current() < org.gradle.util.GradleVersion.version("8.0") -> {
id("io.freefair.lombok") version "5.3.3.3" apply false
}
else -> {
id("io.freefair.lombok") version "6.6.3" apply false
}
}
if (org.gradle.util.GradleVersion.current() >= org.gradle.util.GradleVersion.version("8.0")) {
// XXX: Currently unsupported
} else if (org.gradle.util.GradleVersion.current() >= org.gradle.util.GradleVersion.version("7.0")) {
id("org.kordamp.gradle.jacoco") version "0.47.0"
} else if (org.gradle.util.GradleVersion.current() >= org.gradle.util.GradleVersion.version("5.3")) {
id("org.kordamp.gradle.jacoco") version "0.46.0"
}
}
// XXX: Jacoco plugin only supports Gradle [5.3, 8.0); create empty task on those Gradle versions so that build does not fail
if (org.gradle.util.GradleVersion.current() < org.gradle.util.GradleVersion.version("5.3") || org.gradle.util.GradleVersion.current() >= org.gradle.util.GradleVersion.version("8.0")) {
tasks.register("AggregateJacocoReport")
}
if (!JavaVersion.current().isJava11Compatible) {
throw GradleException("This build must be run with at least Java 11")
}
if (org.gradle.util.GradleVersion.current() < org.gradle.util.GradleVersion.version("4.10")) {
throw GradleException("This build must be run with at least Gradle 4.10")
}
apply(plugin = "net.researchgate.release")
release {
// https://github.com/researchgate/gradle-release/issues/340
// https://github.com/researchgate/gradle-release/issues/281
val gitConfig = getProperty("git") as net.researchgate.release.GitAdapter.GitConfig
gitConfig.requireBranch = "main"
}
if (org.gradle.util.GradleVersion.current() < org.gradle.util.GradleVersion.version("5.0")) {
task<Wrapper>("wrapper") {
distributionType = Wrapper.DistributionType.ALL
}
} else {
tasks.getByName<Wrapper>("wrapper") {
distributionType = Wrapper.DistributionType.ALL
}
}
tasks.getByName("afterReleaseBuild") {
dependsOn(
":common:publish", ":analyzer:publish", ":manipulation:publish", ":cli:publish", ":analyzer:publishPlugins",
":manipulation:publishPlugins"
)
}
// This was tasks.beforeReleaseBuild to hook into the release plugin system, but we are manually handling the task
// ordering
tasks.register("fixupReadme") {
doLast {
if ("true" == System.getProperty("release","") && project == project.rootProject) {
val tmp = File(System.getProperty("java.io.tmpdir"))
val source = File(project.rootDir, "README.md")
val searchString = "https://repo1.maven.org/maven2/org/jboss/gm/analyzer"
if (!source.exists() || Files.readAllLines(source.toPath()).none { s -> s.contains(searchString) }) {
throw GradleException("Unable to find '$searchString' in README.md")
}
project.copy {
from(source)
into(tmp)
filter { line: String ->
if (line.contains(searchString)) {
line.replaceFirst(
"($searchString)(.*)".toRegex(),
"$1/${project.version}/analyzer-${project.version}-init.gradle".replace("-SNAPSHOT", "")
)
} else line
}
}
Files.move(File(tmp, "README.md").toPath(), source.toPath(), StandardCopyOption.REPLACE_EXISTING)
val grgit = Grgit.open(mapOf("currentDir" to project.rootDir))
// Only commit README if there are any changes.
if (!grgit.status().isClean) {
logger.info ("Committing README update")
grgit.commit(mapOf("message" to "Committing README Version Changes", "paths" to setOf("README.md")))
grgit.push()
}
}
}
}
// In https://github.com/researchgate/gradle-release/blob/main/src/main/groovy/net/researchgate/release/ReleasePlugin.groovy#L116,
// the list of task interdependencies is specified. However, as per https://github.com/researchgate/gradle-release/issues/298,
// we want to ensure the tag is done before the build so the manifest (etc.) points to the correct SHA. As the beforeReleaseBuild
// then runs at the wrong point with this change, we manually inject a task (fixupReadme) below.
tasks.getByName("preTagCommit") {
logger.info("Altering preTagCommit to run after checkSnapshotDependencies instead of runBuildTasks")
setMustRunAfter(listOf(tasks["checkSnapshotDependencies"]) )
dependsOn("fixupReadme")
}
tasks.getByName("runBuildTasks") {
logger.info("Altering runBuildTasks to run after createReleaseTag instead of checkSnapshotDependencies")
setMustRunAfter(listOf(tasks["createReleaseTag"]) )
}
tasks.getByName("checkoutMergeFromReleaseBranch") {
logger.info("Altering checkoutMergeFromReleaseBranch to run after runBuildTasks instead of createReleaseTag")
setMustRunAfter(listOf(tasks["runBuildTasks"]))
}
allprojects {
repositories {
mavenCentral()
mavenLocal()
maven {
url = uri("https://repo.gradle.org/gradle/libs-releases-local/")
}
maven {
url = uri("https://oss.sonatype.org/content/repositories/snapshots/")
}
maven {
url = uri("https://maven.repository.redhat.com/ga/")
}
}
apply(plugin = "idea")
}
val isReleaseBuild = ("true" == System.getProperty("release", ""))
if (isReleaseBuild && GradleVersion.current().version != "5.6.4") {
throw GradleException("Gradle 5.6.4 is required to release this project")
}
subprojects {
extra["assertjVersion"] = "3.19.0"
extra["atlasVersion"] = "0.17.2"
extra["bytemanVersion"] = "4.0.15"
extra["commonsBeanVersion"] = "1.9.4"
extra["commonsVersion"] = "2.6"
extra["gradleVersion"] = "5.6.4"
extra["groovyVersion"] = "3.0.17"
extra["ivyVersion"] = "2.5.0"
// Note - this *downgrades* Jackson from what is used in PME. This is due to
// https://github.com/gradle/gradle/issues/24390
// https://github.com/FasterXML/jackson-core/issues/955
// This exclusion isn't required on 7.6.1 and above.
extra["jacksonVersion"] = "2.14.3"
extra["jgitVersion"] = "6.3.0.202209071007-r"
extra["junitVersion"] = "4.13.2"
// Must use 1.3.x series as 1.4.x and above requires JDK11.
extra["logbackVersion"] = "1.3.14"
extra["mavenVersion"] = "3.6.3"
extra["opentelemetryVersion"] = "1.2.0"
extra["ownerVersion"] = "1.0.12"
extra["pmeVersion"] = "4.17"
extra["slf4jVersion"] = "2.0.13"
extra["systemRulesVersion"] = "1.19.0"
if (org.gradle.util.GradleVersion.current() < org.gradle.util.GradleVersion.version("5.4")) {
apply(plugin = "com.diffplug.gradle.spotless")
} else {
apply(plugin = "com.diffplug.spotless")
}
apply(plugin = "com.adarshr.test-logger")
apply(plugin = "io.freefair.lombok")
extra["lombokVersion"] = extensions.findByType(LombokExtension::class)?.version
// XXX: Lombok plugin 3.x < 3.6.1 suffers from <https://github.com/freefair/gradle-plugins/issues/31>
if (org.gradle.util.GradleVersion.current() < org.gradle.util.GradleVersion.version("5.0")
|| org.gradle.util.GradleVersion.current() >= org.gradle.util.GradleVersion.version("5.2")) {
// Don't generate lombok.config files ( https://docs.freefair.io/gradle-plugins/3.6.6/reference/#_lombok_config_handling )
tasks.findByName("generateLombokConfig")?.enabled = false
}
if (project.name == "common" || project.name == "cli") {
apply(plugin = "java-library")
tasks.withType<Jar>().configureEach {
manifest {
attributes["Built-By"] = System.getProperty("user.name")
attributes["Build-Timestamp"] = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ").format(Date())
attributes["Scm-Revision"] = Grgit.open(mapOf("currentDir" to project.rootDir)).use { g -> g.head().id }
attributes["Created-By"] = "Gradle ${gradle.gradleVersion}"
attributes["Build-Jdk"] = System.getProperty("java.version") + " ; " + System.getProperty("java.vendor") + " ; " + System.getProperty("java.vm.version")
attributes["Build-OS"] = System.getProperty("os.name") + " ; " + System.getProperty("os.arch") + " ; " + System.getProperty("os.version")
attributes["Implementation-Version"] = "${project.version}"
}
}
} else {
// Don't apply Gradle plugin code to the cli tool.
apply(plugin = "java-gradle-plugin")
apply(plugin = "com.gradle.plugin-publish")
tasks.withType<ShadowJar>().configureEach {
dependencies {
exclude(dependency("org.slf4j:slf4j-api:${project.extra.get("slf4jVersion")}"))
}
}
}
apply(plugin = "signing")
apply(plugin = "maven-publish")
apply(plugin = "net.linguica.maven-settings")
val sourcesJar by tasks.registering(Jar::class) {
archiveClassifier.set("sources")
from(sourceSets["main"].allSource)
}
val javadocJar by tasks.registering(Jar::class) {
archiveClassifier.set("javadoc")
from(tasks["javadoc"])
}
// XXX: The code below emulates test fixtures as this feature only exists in Gradle 5.6+
val outputDirectories by configurations.creating {
}
val testFixturesCompile by configurations.creating {
extendsFrom(configurations["implementation"])
}
configurations.create("testFixturesRuntime") {
extendsFrom(configurations["runtimeOnly"], configurations["testFixturesCompile"])
}
val testFixturesUsageImplementation by configurations.creating {
extendsFrom(configurations["testFixturesCompile"], configurations["outputDirectories"])
}
val testFixturesUsageRuntimeOnly by configurations.creating {
extendsFrom(configurations["testFixturesRuntime"], configurations["testFixturesUsageImplementation"])
}
configurations["testImplementation"].extendsFrom(testFixturesUsageImplementation)
configurations["testRuntimeOnly"].extendsFrom(testFixturesUsageRuntimeOnly)
sourceSets.create("testFixtures") {
java.srcDir("src/testFixtures/java")
resources.srcDir("src/testFixtures/resources")
compileClasspath = sourceSets["main"].output + configurations["testFixturesCompile"]
runtimeClasspath = output + compileClasspath + configurations["testFixturesRuntime"]
}
dependencies {
outputDirectories(sourceSets["testFixtures"].output)
testFixturesUsageImplementation(project(project.path))
testFixturesCompile("org.slf4j:slf4j-api:${project.extra.get("slf4jVersion")}")
testFixturesCompile("junit:junit:${project.extra.get("junitVersion")}")
testFixturesCompile(gradleApi())
}
val testFixturesJar by tasks.registering(Jar::class) {
archiveClassifier.set("test-fixtures")
from(sourceSets["testFixtures"].output)
}
if (project.name == "common") {
artifacts {
add("archives", tasks["testFixturesJar"])
add("testFixturesCompile", testFixturesJar)
}
}
if (project.name != "common") {
/*
* The configuration below has been created by reading the documentation at:
* https://imperceptiblethoughts.com/shadow/plugins/
*
* Another great source of information is the configuration of the shadow plugin itself:
* https://github.com/johnrengelman/shadow/blob/main/build.gradle
*/
apply(plugin = "com.github.johnrengelman.shadow")
// Make assemble/build task depend on shadowJar
tasks["assemble"].dependsOn(tasks["shadowJar"])
tasks.withType<ShadowJar>().configureEach {
// ensure that a single jar is built which is the shadowed one
archiveClassifier.set("")
// no need to add analyzer.init.gradle in the jar since it will never be used from inside the plugin itself
exclude("analyzer-init.gradle")
// XXX: Skip minimization for Gradle 4.10 (ShadowJar 4.0.1) due to missing classes
if (org.gradle.util.GradleVersion.current() >= org.gradle.util.GradleVersion.version("5.0")) {
// Minimise the resulting uber-jars to ensure we don't have massive jars
minimize {
// Sometimes minimisation takes away too much ... ensure we keep these.
exclude(dependency("io.opentelemetry:.*"))
exclude(dependency("com.fasterxml.jackson.core:.*:.*"))
exclude(dependency("org.commonjava.maven.ext:.*:.*"))
exclude(dependency("org.commonjava.maven.atlas:.*:.*"))
exclude(dependency("org.aeonbits.owner:.*:.*"))
exclude(dependency("org.slf4j:.*:.*"))
exclude(dependency("org.apache.maven:.*:.*"))
exclude(dependency("org.apache.ivy:.*:.*"))
exclude(dependency("com.konghq:.*:.*"))
}
}
doFirst {
manifest {
attributes["Built-By"] = System.getProperty("user.name")
attributes["Build-Timestamp"] = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ").format(Date())
attributes["Scm-Revision"] = Grgit.open(mapOf("currentDir" to project.rootDir)).use { g -> g.head().id }
attributes["Created-By"] = "Gradle ${gradle.gradleVersion}"
attributes["Build-Jdk"] = System.getProperty("java.version") + " ; " + System.getProperty("java.vendor") + " ; " + System.getProperty("java.vm.version")
attributes["Build-OS"] = System.getProperty("os.name") + " ; " + System.getProperty("os.arch") + " ; " + System.getProperty("os.version")
attributes["Implementation-Version"] = "${project.version}"
}
}
isZip64 = true
}
// configure publishing of the shadowJar
configure<PublishingExtension> {
publications {
create<MavenPublication>("shadow") {
project.shadow.component(this)
artifact(sourcesJar.get())
artifact(javadocJar.get())
// we publish the init gradle file to make it easy for tools that use
// the plugin to set it up without having to create their own init gradle file
if (project.name == "analyzer") {
artifact("${sourceSets["main"].output.resourcesDir}/analyzer-init.gradle") {
classifier = "init"
extension = "gradle"
}
}
generatePom()
}
}
generateRepositories(this, this@Build_gradle)
}
if (isReleaseBuild) {
signing {
useGpgCmd()
sign(publishing.publications["shadow"])
}
}
} else {
publishing {
publications {
create<MavenPublication>("mavenJava") {
from(components["java"])
artifact(sourcesJar.get())
artifact(javadocJar.get())
artifact(testFixturesJar.get())
generatePom()
}
}
generateRepositories(this, this@Build_gradle)
}
if (isReleaseBuild) {
signing {
useGpgCmd()
sign(publishing.publications["mavenJava"])
}
}
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
testlogger {
// Some of our tests take a _long_ time ; remove spurious warnings.
slowThreshold = 120000
// Nicer looking theme than default.
theme = ThemeType.MOCHA
}
spotless {
java {
importOrderFile("$rootDir/ide-config/eclipse.importorder")
eclipse().configFile("$rootDir/ide-config/eclipse-format.xml")
}
}
tasks.withType<JavaCompile>().configureEach {
dependsOn("spotlessApply")
}
if (project.name != "cli") {
// Exclude logback from dependency tree.
configurations {
"implementation" {
exclude(group = "ch.qos.logback", module = "logback-classic")
}
"implementation" {
exclude(group = "ch.qos.logback", module = "logback-core")
}
}
}
}
fun generateRepositories(publishingExtension: PublishingExtension, buildGradle: Build_gradle) {
publishingExtension.repositories {
if (buildGradle.isReleaseBuild) {
maven {
name = "sonatype-nexus-staging"
url = project.uri("https://oss.sonatype.org/service/local/staging/deploy/maven2")
}
} else {
maven {
name = "sonatype-nexus-snapshots"
url = project.uri("https://oss.sonatype.org/content/repositories/snapshots")
}
}
}
}
fun MavenPublication.generatePom() {
pom {
name.set("Gradle Manipulation Extension")
description.set("A tool to work with ProjectNCL to manipulate Gradle builds.")
url.set("https://github.com/project-ncl/gradle-manipulator")
packaging = "jar"
licenses {
license {
name.set("The Apache License, Version 2.0")
url.set("https://www.apache.org/licenses/LICENSE-2.0.txt")
}
}
developers {
developer {
id.set("geoand")
name.set("Georgios Andrianakis")
email.set("gandrian@redhat.com")
}
developer {
id.set("rnc")
name.set("Nick Cross")
email.set("ncross@redhat.com")
}
developer {
id.set("TomasHofman")
name.set("Tomas Hofman")
email.set("thofman@redhat.com")
}
developer {
id.set("metacosm")
name.set("Chris Laprun")
email.set("claprun@redhat.com")
}
developer {
id.set("dwalluck")
name.set("David Walluck")
email.set("dwalluck@redhat.com")
}
}
scm {
connection.set("scm:git:http://github.com/project-ncl/gradle-manipulator.git")
developerConnection.set("scm:git:git@github.com:project-ncl/gradle-manipulator.git")
url.set("https://github.com/project-ncl/gradle-manipulator")
}
}
}