-
Notifications
You must be signed in to change notification settings - Fork 13
/
build.gradle.kts
281 lines (255 loc) · 9.22 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
import com.diffplug.gradle.spotless.SpotlessExtension
import com.vanniktech.maven.publish.JavaLibrary
import com.vanniktech.maven.publish.JavadocJar
import com.vanniktech.maven.publish.SonatypeHost
import net.ltgt.gradle.errorprone.CheckSeverity
import net.ltgt.gradle.errorprone.errorprone
plugins {
`java-library`
alias(libs.plugins.errorprone)
alias(libs.plugins.git)
alias(libs.plugins.maven)
alias(libs.plugins.osdetector)
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
// The releaseVersion property is set on official releases in the release.yml workflow.
// If not specified, we attempt to calculate a snapshot version based on the last tagged release.
// So if the local build's last tag was v0.1.9, this will set snapshotVersion to 0.1.10-SNAPSHOT.
// If this fails for any reason, we'll fall back to using 0.0.0-SNAPSHOT version.
val versionDetails: groovy.lang.Closure<com.palantir.gradle.gitversion.VersionDetails> by extra
val details = versionDetails()
var snapshotVersion = "0.0.0-SNAPSHOT"
val matchResult = """^v(\d+)\.(\d+)\.(\d+)$""".toRegex().matchEntire(details.lastTag)
if (matchResult != null) {
val (major, minor, patch) = matchResult.destructured
snapshotVersion = "$major.$minor.${patch.toInt() + 1}-SNAPSHOT"
}
val releaseVersion = project.findProperty("releaseVersion") as String? ?: snapshotVersion
val buf: Configuration by configurations.creating
val bufLicenseHeaderCLIFile = project.layout.buildDirectory.file("gobin/license-header").get().asFile
val bufLicenseHeaderCLIPath: String = bufLicenseHeaderCLIFile.absolutePath
tasks.register("configureBuf") {
description = "Installs the Buf CLI."
File(buf.asPath).setExecutable(true)
}
tasks.register<Exec>("installLicenseHeader") {
description = "Installs the Buf license-header CLI."
environment("GOBIN", bufLicenseHeaderCLIFile.parentFile.absolutePath)
outputs.file(bufLicenseHeaderCLIFile)
commandLine("go", "install", "github.com/bufbuild/buf/private/pkg/licenseheader/cmd/license-header@v${libs.versions.buf.get()}")
}
tasks.register<Exec>("licenseHeader") {
dependsOn("installLicenseHeader")
description = "Runs the Buf license-header CLI."
commandLine(
bufLicenseHeaderCLIPath,
"--license-type",
"apache",
"--copyright-holder",
"Buf Technologies, Inc.",
"--year-range",
project.findProperty("license-header.years")!!.toString(),
"--ignore",
"src/main/java/build/buf/validate/",
"--ignore",
"conformance/src/main/java/build/buf/validate/conformance/",
"--ignore",
"src/main/resources/buf/validate/",
)
}
tasks.register<Exec>("generateTestSourcesImports") {
dependsOn("exportProtovalidateModule")
description = "Generates code with buf generate --include-imports for unit tests."
commandLine(
buf.asPath,
"generate",
"--template",
"src/test/resources/proto/buf.gen.imports.yaml",
"--include-imports",
)
}
tasks.register<Exec>("generateTestSourcesNoImports") {
dependsOn("exportProtovalidateModule")
description = "Generates code with buf generate --include-imports for unit tests."
commandLine(buf.asPath, "generate", "--template", "src/test/resources/proto/buf.gen.noimports.yaml")
}
tasks.register("generateTestSources") {
dependsOn("generateTestSourcesImports", "generateTestSourcesNoImports")
description = "Generates code with buf generate for unit tests"
}
tasks.register<Exec>("exportProtovalidateModule") {
dependsOn("configureBuf")
description = "Exports the bufbuild/protovalidate module sources to src/main/resources."
commandLine(
buf.asPath,
"export",
"buf.build/bufbuild/protovalidate:${project.findProperty("protovalidate.version")}",
"--output",
"src/main/resources",
)
}
tasks.register<Exec>("generateSources") {
dependsOn("exportProtovalidateModule")
description = "Generates sources for the bufbuild/protovalidate module sources to src/main/java."
commandLine(buf.asPath, "generate", "--template", "buf.gen.yaml", "src/main/resources")
}
tasks.register<Exec>("generateConformance") {
dependsOn("configureBuf")
description = "Generates sources for the bufbuild/protovalidate-testing module to conformance/src/main/java."
commandLine(
buf.asPath,
"generate",
"--template",
"conformance/buf.gen.yaml",
"-o",
"conformance/",
"buf.build/bufbuild/protovalidate-testing:${project.findProperty("protovalidate.version")}",
)
}
tasks.register("generate") {
description = "Generates sources with buf generate and buf export."
dependsOn(
"generateTestSources",
"generateSources",
"generateConformance",
"licenseHeader",
)
}
tasks.withType<JavaCompile> {
dependsOn("generateTestSources")
if (JavaVersion.current().isJava9Compatible) {
doFirst {
options.compilerArgs = mutableListOf("--release", "8")
}
}
// Disable errorprone on generated code
options.errorprone.excludedPaths.set("(.*/src/main/java/build/buf/validate/.*|.*/build/generated/.*)")
if (!name.lowercase().contains("test")) {
options.errorprone {
check("NullAway", CheckSeverity.ERROR)
option("NullAway:AnnotatedPackages", "build.buf.protovalidate")
}
}
}
tasks.withType<Javadoc> {
val stdOptions = options as StandardJavadocDocletOptions
stdOptions.addBooleanOption("Xwerror", true)
// Ignore warnings for generated code.
stdOptions.addBooleanOption("Xdoclint/package:-build.buf.validate,-build.buf.validate.priv", true)
}
tasks.withType<GenerateModuleMetadata> {
suppressedValidationErrors.add("enforced-platform")
}
buildscript {
dependencies {
classpath(libs.maven.plugin)
classpath(libs.spotless)
}
}
sourceSets {
test {
java {
srcDir(layout.buildDirectory.dir("generated/test-sources/bufgen"))
}
}
}
apply(plugin = "com.diffplug.spotless")
configure<SpotlessExtension> {
java {
targetExclude("src/main/java/build/buf/validate/**/*.java", "build/generated/test-sources/bufgen/**/*.java")
}
kotlinGradle {
ktlint()
target("**/*.kts")
}
}
allprojects {
version = releaseVersion
repositories {
mavenCentral()
}
apply(plugin = "com.diffplug.spotless")
configure<SpotlessExtension> {
isEnforceCheck = false // Disables lint on gradle builds.
java {
importOrder()
removeUnusedImports()
replaceRegex("Remove wildcard imports", "import\\s+[^\\*\\s]+\\*;(\\r\\n|\\r|\\n)", "$1")
googleJavaFormat()
endWithNewline()
trimTrailingWhitespace()
}
}
tasks.withType<Jar>().configureEach {
if (name == "jar") {
manifest {
attributes("Implementation-Version" to releaseVersion)
}
}
}
tasks.withType<Test>().configureEach {
useJUnitPlatform()
}
}
mavenPublishing {
val isAutoReleased = project.hasProperty("signingInMemoryKey")
publishToMavenCentral(SonatypeHost.S01)
if (isAutoReleased) {
signAllPublications()
}
coordinates("build.buf", "protovalidate", releaseVersion)
pomFromGradleProperties()
configure(
JavaLibrary(
// configures the -javadoc artifact, possible values:
// - `JavadocJar.None()` don't publish this artifact
// - `JavadocJar.Empty()` publish an empty jar
// - `JavadocJar.Javadoc()` to publish standard javadocs
javadocJar = JavadocJar.Javadoc(),
// whether to publish a sources jar
sourcesJar = true,
),
)
pom {
name.set("protovalidate-java")
group = "build.buf"
description.set("Protocol Buffer Validation")
url.set("https://github.com/bufbuild/protovalidate-java")
licenses {
license {
name.set("The Apache Software License, Version 2.0")
url.set("https://www.apache.org/licenses/LICENSE-2.0.txt")
distribution.set("repo")
}
}
developers {
developer {
id.set("bufbuild")
name.set("Buf Technologies")
}
}
scm {
url.set("https://github.com/bufbuild/protovalidate-java")
connection.set("scm:git:https://github.com/bufbuild/protovalidate-java.git")
developerConnection.set("scm:git:ssh://[email protected]/bufbuild/protovalidate-java.git")
}
}
}
dependencies {
annotationProcessor(libs.nullaway)
api(libs.protobuf.java)
implementation(enforcedPlatform(libs.cel))
implementation(libs.cel.core)
implementation(libs.guava)
implementation(libs.ipaddress)
implementation(libs.jakarta.mail.api)
buf("build.buf:buf:${libs.versions.buf.get()}:${osdetector.classifier}@exe")
testImplementation(libs.assertj)
testImplementation(platform(libs.junit.bom))
testImplementation("org.junit.jupiter:junit-jupiter")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
errorprone(libs.errorprone)
}