Skip to content

Commit c8ff5ad

Browse files
author
Abhijit Sarkar
committed
Group task configurations in the tasks container
1 parent 3904d97 commit c8ff5ad

File tree

2 files changed

+69
-53
lines changed

2 files changed

+69
-53
lines changed

client/build.gradle.kts

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ dependencies {
2525
errorprone(libs.errorprone)
2626
}
2727

28-
val javaVersion = JavaLanguageVersion.of(rootDir.resolve(".java-version").readText(Charsets.UTF_8).trim())
28+
val javaVersion =
29+
JavaLanguageVersion.of(
30+
rootDir.resolve(".java-version").readText(Charsets.UTF_8).trim(),
31+
)
2932

3033
java {
3134
toolchain {
@@ -44,30 +47,35 @@ spotless {
4447
}
4548
}
4649

47-
val ci: Boolean by lazy { listOf("CI").any { System.getenv(it) != null } }
48-
val spotlessTasks = arrayOf("spotlessApply", "spotlessCheck")
49-
val spotlessTask = spotlessTasks[true.compareTo(ci)] // true > false
50+
val ci: Boolean by lazy { System.getenv("CI") != null }
5051

51-
tasks.named(spotlessTask) {
52-
enabled = false
53-
}
52+
/*
53+
DO NOT use existing(Task::class) for configuring tasks.
54+
existing() if not referenced from another task is dropped on the floor!
55+
Use withTask() instead.
56+
*/
57+
tasks {
58+
test {
59+
useJUnitPlatform()
60+
testLogging {
61+
showStandardStreams = true
62+
}
63+
// Suppress warning: Sharing is only supported for boot loader classes...
64+
// https://stackoverflow.com/q/54205486/839733
65+
jvmArgs("-Xshare:off")
66+
}
5467

55-
tasks.named("check") {
56-
dependsOn(spotlessTasks[0])
57-
}
68+
withType<SpotBugsTask> {
69+
reports.create("html") {
70+
required = !ci
71+
}
72+
}
5873

59-
tasks.withType<Test> {
60-
useJUnitPlatform()
61-
testLogging {
62-
showStandardStreams = true
74+
val spotlessApply by named("spotlessApply") {
75+
enabled = !ci
6376
}
64-
// Suppress warning: Sharing is only supported for boot loader classes...
65-
// https://stackoverflow.com/q/54205486/839733
66-
jvmArgs("-Xshare:off")
67-
}
6877

69-
tasks.withType<SpotBugsTask> {
70-
reports.create("html") {
71-
required = !ci
78+
named("spotlessCheck") {
79+
dependsOn(spotlessApply)
7280
}
7381
}

lib/build.gradle.kts

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -45,24 +45,6 @@ kotlin {
4545
}
4646
}
4747

48-
tasks.withType<Jar> {
49-
manifest {
50-
attributes("Automatic-Module-Name" to "com.asarkar.grpc.test")
51-
}
52-
archiveBaseName = rootProject.name
53-
}
54-
55-
tasks.withType<Test> {
56-
useJUnitPlatform()
57-
testLogging {
58-
showStandardStreams = true
59-
}
60-
exclude("**/ignore/**")
61-
// Suppress warning: Sharing is only supported for boot loader classes...
62-
// https://stackoverflow.com/q/54205486/839733
63-
jvmArgs("-Xshare:off")
64-
}
65-
6648
val ci: Boolean by lazy { System.getenv("CI") != null }
6749

6850
ktlint {
@@ -73,15 +55,6 @@ ktlint {
7355
additionalEditorconfig = mapOf("max_line_length" to "100")
7456
}
7557

76-
tasks.withType<KtLintFormatTask> {
77-
enabled = !ci
78-
}
79-
80-
tasks.withType<KtLintCheckTask> {
81-
val fmtTaskName = name.replace("Check", "Format")
82-
dependsOn(tasks.named(fmtTaskName))
83-
}
84-
8558
val gitHubUsername: String by project
8659
val gitHubRepo: String by lazy {
8760
System.getenv("GITHUB_REPOSITORY") ?: "$gitHubUsername/${rootProject.name}"
@@ -110,11 +83,6 @@ val licenseUrl: String by project
11083

11184
version = projectVersion
11285

113-
// https://github.com/vanniktech/gradle-maven-publish-plugin/issues/966
114-
tasks.withType<JavadocJar> {
115-
archiveFileName = "${rootProject.name}-javadoc.jar"
116-
}
117-
11886
mavenPublishing {
11987
configure(
12088
KotlinJvm(
@@ -150,3 +118,43 @@ mavenPublishing {
150118
}
151119
}
152120
}
121+
122+
/*
123+
DO NOT use existing(Task::class) for configuring tasks.
124+
existing() if not referenced from another task is dropped on the floor!
125+
Use withTask() instead.
126+
*/
127+
tasks {
128+
withType<Jar> {
129+
manifest {
130+
attributes("Automatic-Module-Name" to "com.asarkar.grpc.test")
131+
}
132+
archiveBaseName = rootProject.name
133+
}
134+
135+
test {
136+
useJUnitPlatform()
137+
testLogging {
138+
showStandardStreams = true
139+
}
140+
exclude("**/ignore/**")
141+
// Suppress warning: Sharing is only supported for boot loader classes...
142+
// https://stackoverflow.com/q/54205486/839733
143+
jvmArgs("-Xshare:off")
144+
}
145+
146+
// https://github.com/vanniktech/gradle-maven-publish-plugin/issues/966
147+
withType<JavadocJar> {
148+
archiveFileName = "${rootProject.name}-javadoc.jar"
149+
}
150+
151+
withType<KtLintFormatTask> {
152+
enabled = !ci
153+
}
154+
155+
withType<KtLintCheckTask> {
156+
val fmtTaskName = name.replace("Check", "Format")
157+
val fmtTask by named(fmtTaskName)
158+
dependsOn(fmtTask)
159+
}
160+
}

0 commit comments

Comments
 (0)