-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild.gradle.kts
195 lines (175 loc) · 6.87 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
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
`java-gradle-plugin`
`kotlin-dsl`
`maven-publish`
id("com.gradle.plugin-publish") version "1.3.0"
id("com.diffplug.spotless") version "6.25.0"
id("com.android.lint") version "8.7.3"
id("org.nosphere.gradle.github.actions") version "1.4.0"
}
group = "net.ltgt.gradle"
// Make sure Gradle Module Metadata targets the appropriate JVM version
tasks.withType<JavaCompile>().configureEach {
options.release.set(8)
}
tasks.withType<KotlinCompile>().configureEach {
// See https://jakewharton.com/kotlins-jdk-release-compatibility-flag/
compilerOptions.freeCompilerArgs.add("-Xjdk-release=1.8")
compilerOptions.jvmTarget = JvmTarget.JVM_1_8
// For Gradle 6.8 compatibility. Gradle 6.8 embeds Kotlin 1.4.
// https://docs.gradle.org/current/userguide/compatibility.html#kotlin
@Suppress("DEPRECATION")
compilerOptions.apiVersion = KotlinVersion.KOTLIN_1_4
@Suppress("DEPRECATION")
compilerOptions.languageVersion = KotlinVersion.KOTLIN_1_4
compilerOptions.allWarningsAsErrors = true
// Using Kotlin 1.4 above emits a warning that would then fail the build with allWarningsAsErrors
compilerOptions.freeCompilerArgs.add("-Xsuppress-version-warnings")
}
gradle.taskGraph.whenReady {
if (hasTask(":publishPlugins")) {
check(cmd("git", "diff", "--quiet", "--exit-code").waitFor() == 0) { "Working tree is dirty" }
val process = cmd("git", "describe", "--exact-match")
check(process.waitFor() == 0) { "Version is not tagged" }
version = process.text.trim().removePrefix("v")
}
}
// See https://github.com/gradle/gradle/issues/7974
val additionalPluginClasspath by configurations.creating
val errorpronePluginVersion = "4.1.0"
val errorproneVersion = "2.36.0"
repositories {
mavenCentral()
google()
gradlePluginPortal {
content {
includeGroupByRegex("""net\.ltgt\..*""")
}
}
}
dependencies {
compileOnly("net.ltgt.gradle:gradle-errorprone-plugin:$errorpronePluginVersion")
additionalPluginClasspath("net.ltgt.gradle:gradle-errorprone-plugin:$errorpronePluginVersion")
}
tasks {
pluginUnderTestMetadata {
this.pluginClasspath.from(additionalPluginClasspath)
}
check {
dependsOn(testing.suites)
}
}
testing {
suites {
withType<JvmTestSuite>().configureEach {
useJUnitJupiter("5.11.3")
dependencies {
implementation("com.google.truth:truth:1.4.4") {
// See https://github.com/google/truth/issues/333
exclude(group = "junit", module = "junit")
}
runtimeOnly("junit:junit:4.13.2") {
// See https://github.com/google/truth/issues/333
because("Truth needs it")
}
}
targets.configureEach {
testTask {
testLogging {
showExceptions = true
showStackTraces = true
exceptionFormat = TestExceptionFormat.FULL
}
}
}
}
val test by getting(JvmTestSuite::class) {
dependencies {
implementation(project())
implementation("net.ltgt.gradle:gradle-errorprone-plugin:$errorpronePluginVersion")
implementation("com.google.errorprone:error_prone_check_api:$errorproneVersion") {
exclude(group = "com.google.errorprone", module = "javac")
}
}
}
register<JvmTestSuite>("integrationTest") {
dependencies {
implementation(gradleTestKit())
}
// make plugin-under-test-metadata.properties accessible to TestKit
gradlePlugin.testSourceSet(sources)
targets.configureEach {
testTask {
shouldRunAfter(test)
val testJavaToolchain = project.findProperty("test.java-toolchain")
testJavaToolchain?.also {
val launcher =
project.javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(testJavaToolchain.toString()))
}
val metadata = launcher.get().metadata
systemProperty("test.java-version", metadata.languageVersion.asInt())
systemProperty("test.java-home", metadata.installationPath.asFile.canonicalPath)
}
val testGradleVersion = project.findProperty("test.gradle-version")
testGradleVersion?.also { systemProperty("test.gradle-version", testGradleVersion) }
systemProperty("errorprone.version", errorproneVersion)
}
}
}
}
}
gradlePlugin {
website.set("https://github.com/tbroyer/gradle-nullaway-plugin")
vcsUrl.set("https://github.com/tbroyer/gradle-nullaway-plugin")
plugins {
register("nullaway") {
id = "net.ltgt.nullaway"
displayName = "Adds NullAway DSL to Gradle Error Prone plugin"
description = "Adds NullAway DSL to Gradle Error Prone plugin"
implementationClass = "net.ltgt.gradle.nullaway.NullAwayPlugin"
tags.addAll("javac", "error-prone", "nullaway", "nullability")
}
}
}
publishing {
publications.withType<MavenPublication>().configureEach {
pom {
name.set("Adds NullAway DSL to Gradle Error Prone plugin")
description.set("Adds NullAway DSL to Gradle Error Prone plugin")
url.set("https://github.com/tbroyer/gradle-nullaway-plugin")
licenses {
license {
name.set("Apache-2.0")
url.set("https://www.apache.org/licenses/LICENSE-2.0")
}
}
developers {
developer {
name.set("Thomas Broyer")
email.set("t.broyer@ltgt.net")
}
}
scm {
connection.set("https://github.com/tbroyer/gradle-nullaway-plugin.git")
developerConnection.set("scm:git:ssh://github.com:tbroyer/gradle-nullaway-plugin.git")
url.set("https://github.com/tbroyer/gradle-nullaway-plugin")
}
}
}
}
spotless {
kotlinGradle {
ktlint("1.4.1")
}
kotlin {
ktlint("1.4.1")
}
}
fun cmd(vararg cmdarray: String) = Runtime.getRuntime().exec(cmdarray, null, rootDir)
val Process.text: String
get() = inputStream.bufferedReader().readText()