-
Notifications
You must be signed in to change notification settings - Fork 820
/
build-logic.style.gradle.kts
110 lines (99 loc) · 3.41 KB
/
build-logic.style.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
import com.github.autostyle.gradle.AutostyleTask
import de.thetaphi.forbiddenapis.gradle.CheckForbiddenApis
import org.gradle.kotlin.dsl.apply
import org.gradle.language.base.plugins.LifecycleBasePlugin
plugins {
id("build-logic.build-params")
}
if (!buildParameters.skipAutostyle) {
apply(plugin = "build-logic.autostyle")
if (!buildParameters.skipCheckstyle) {
tasks.withType<Checkstyle>().configureEach {
mustRunAfter(tasks.withType<AutostyleTask>())
}
}
}
val skipCheckstyle = buildParameters.skipCheckstyle || run {
logger.info("Checkstyle requires Java 11+")
buildParameters.buildJdkVersion < 11
}
// OpenRewrite Gradle plugin applies to allprojects when it is applied to the root project
// So the workaround is to avoid applying openrewrite to the root
val skipOpenrewrite = project == rootProject || buildParameters.skipOpenrewrite
if (!skipOpenrewrite) {
apply(plugin = "build-logic.openrewrite")
}
if (!skipCheckstyle) {
apply(plugin = "build-logic.checkstyle")
}
if (!buildParameters.skipForbiddenApis) {
apply(plugin = "build-logic.forbidden-apis")
}
plugins.withId("java-base") {
if (buildParameters.enableCheckerframework) {
apply(plugin = "build-logic.checkerframework")
}
if (buildParameters.enableErrorprone) {
apply(plugin = "build-logic.errorprone")
}
if (buildParameters.spotbugs) {
apply(plugin = "build-logic.spotbugs")
}
}
if (!buildParameters.skipAutostyle || !skipCheckstyle || !buildParameters.skipForbiddenApis || !skipOpenrewrite) {
tasks.register("style") {
group = LifecycleBasePlugin.VERIFICATION_GROUP
description = "Formats code (license header, import order, whitespace at end of line, ...) and executes Checkstyle verifications"
if (!buildParameters.skipAutostyle) {
dependsOn("autostyleApply")
}
if (!skipOpenrewrite) {
dependsOn("rewriteRun")
}
if (!skipCheckstyle) {
dependsOn("checkstyleAll")
}
if (!buildParameters.skipForbiddenApis) {
dependsOn("forbiddenApis")
}
}
tasks.register("styleCheck") {
group = LifecycleBasePlugin.VERIFICATION_GROUP
description = "Report code style violations (license header, import order, whitespace at end of line, ...)"
if (!buildParameters.skipAutostyle) {
dependsOn("autostyleCheck")
}
if (!skipOpenrewrite) {
dependsOn("rewriteDryRun")
}
if (!skipCheckstyle) {
dependsOn("checkstyleAll")
}
if (!buildParameters.skipForbiddenApis) {
dependsOn("forbiddenApis")
}
}
}
// OpenRewrite fixes many warnings, so it should run the first
if (!skipOpenrewrite) {
if (!buildParameters.skipForbiddenApis) {
tasks.withType<CheckForbiddenApis>().configureEach {
mustRunAfter("rewriteRun", "rewriteDryRun")
}
}
if (!buildParameters.skipCheckstyle) {
tasks.withType<Checkstyle>().configureEach {
mustRunAfter("rewriteRun", "rewriteDryRun")
}
}
if (!buildParameters.skipAutostyle) {
tasks.withType<AutostyleTask>().configureEach {
mustRunAfter("rewriteRun", "rewriteDryRun")
}
}
}
if (!buildParameters.skipAutostyle) {
tasks.withType<Checkstyle>().configureEach {
mustRunAfter(tasks.withType<AutostyleTask>())
}
}