@@ -10,6 +10,7 @@ plugins {
10
10
alias(libs.plugins.errorprone)
11
11
alias(libs.plugins.git)
12
12
alias(libs.plugins.maven)
13
+ alias(libs.plugins.osdetector)
13
14
}
14
15
15
16
java {
@@ -31,23 +32,20 @@ if (matchResult != null) {
31
32
}
32
33
val releaseVersion = project.findProperty(" releaseVersion" ) as String? ? : snapshotVersion
33
34
34
- val bufCLIFile = project.layout.buildDirectory.file(" gobin/buf" ).get().asFile
35
- val bufCLIPath: String = bufCLIFile.absolutePath
35
+ val buf: Configuration by configurations.creating
36
36
val bufLicenseHeaderCLIFile = project.layout.buildDirectory.file(" gobin/license-header" ).get().asFile
37
37
val bufLicenseHeaderCLIPath: String = bufLicenseHeaderCLIFile.absolutePath
38
38
39
- tasks.register< Exec >( " installBuf " ) {
39
+ tasks.register( " configureBuf " ) {
40
40
description = " Installs the Buf CLI."
41
- environment(" GOBIN" , bufCLIFile.parentFile.absolutePath)
42
- outputs.file(bufCLIFile)
43
- commandLine(" go" , " install" , " github.com/bufbuild/buf/cmd/buf@latest" )
41
+ File (buf.asPath).setExecutable(true )
44
42
}
45
43
46
44
tasks.register<Exec >(" installLicenseHeader" ) {
47
45
description = " Installs the Buf license-header CLI."
48
46
environment(" GOBIN" , bufLicenseHeaderCLIFile.parentFile.absolutePath)
49
47
outputs.file(bufLicenseHeaderCLIFile)
50
- commandLine(" go" , " install" , " github.com/bufbuild/buf/private/pkg/licenseheader/cmd/license-header@latest " )
48
+ commandLine(" go" , " install" , " github.com/bufbuild/buf/private/pkg/licenseheader/cmd/license-header@v ${libs.versions.buf.get()} " )
51
49
}
52
50
53
51
tasks.register<Exec >(" licenseHeader" ) {
@@ -69,10 +67,10 @@ tasks.register<Exec>("licenseHeader") {
69
67
}
70
68
71
69
tasks.register<Exec >(" generateTestSourcesImports" ) {
72
- dependsOn(" installBuf " )
70
+ dependsOn(" configureBuf " )
73
71
description = " Generates code with buf generate --include-imports for unit tests."
74
72
commandLine(
75
- bufCLIPath ,
73
+ buf.asPath ,
76
74
" generate" ,
77
75
" --template" ,
78
76
" src/test/resources/proto/buf.gen.imports.yaml" ,
@@ -82,9 +80,9 @@ tasks.register<Exec>("generateTestSourcesImports") {
82
80
}
83
81
84
82
tasks.register<Exec >(" generateTestSourcesNoImports" ) {
85
- dependsOn(" installBuf " )
83
+ dependsOn(" configureBuf " )
86
84
description = " Generates code with buf generate --include-imports for unit tests."
87
- commandLine(bufCLIPath , " generate" , " --template" , " src/test/resources/proto/buf.gen.noimports.yaml" , " src/test/resources/proto" )
85
+ commandLine(buf.asPath , " generate" , " --template" , " src/test/resources/proto/buf.gen.noimports.yaml" , " src/test/resources/proto" )
88
86
}
89
87
90
88
tasks.register(" generateTestSources" ) {
@@ -93,10 +91,10 @@ tasks.register("generateTestSources") {
93
91
}
94
92
95
93
tasks.register<Exec >(" exportProtovalidateModule" ) {
96
- dependsOn(" installBuf " )
94
+ dependsOn(" configureBuf " )
97
95
description = " Exports the bufbuild/protovalidate module sources to src/main/resources."
98
96
commandLine(
99
- bufCLIPath ,
97
+ buf.asPath ,
100
98
" export" ,
101
99
" buf.build/bufbuild/protovalidate:${project.findProperty(" protovalidate.version" )} " ,
102
100
" --output" ,
@@ -105,16 +103,16 @@ tasks.register<Exec>("exportProtovalidateModule") {
105
103
}
106
104
107
105
tasks.register<Exec >(" generateSources" ) {
108
- dependsOn(" installBuf " )
106
+ dependsOn(" configureBuf " )
109
107
description = " Generates sources for the bufbuild/protovalidate module sources to src/main/java."
110
- commandLine(bufCLIPath , " generate" , " --template" , " buf.gen.yaml" , " src/main/resources" )
108
+ commandLine(buf.asPath , " generate" , " --template" , " buf.gen.yaml" , " src/main/resources" )
111
109
}
112
110
113
111
tasks.register<Exec >(" generateConformance" ) {
114
- dependsOn(" installBuf " )
112
+ dependsOn(" configureBuf " )
115
113
description = " Generates sources for the bufbuild/protovalidate-testing module to conformance/src/main/java."
116
114
commandLine(
117
- bufCLIPath ,
115
+ buf.asPath ,
118
116
" generate" ,
119
117
" --template" ,
120
118
" conformance/buf.gen.yaml" ,
@@ -193,14 +191,10 @@ allprojects {
193
191
version = releaseVersion
194
192
repositories {
195
193
mavenCentral()
196
- maven {
197
- name = " buf"
198
- url = uri(" https://buf.build/gen/maven" )
199
- }
200
194
}
201
195
apply (plugin = " com.diffplug.spotless" )
202
196
configure<SpotlessExtension > {
203
- setEnforceCheck( false ) // Disables lint on gradle builds.
197
+ isEnforceCheck = false // Disables lint on gradle builds.
204
198
java {
205
199
importOrder()
206
200
removeUnusedImports()
@@ -276,9 +270,12 @@ dependencies {
276
270
implementation(libs.ipaddress)
277
271
implementation(libs.jakarta.mail.api)
278
272
273
+ buf(" build.buf:buf:${libs.versions.buf.get()} :${osdetector.classifier} @exe" )
274
+
279
275
testImplementation(libs.assertj)
280
276
testImplementation(platform(libs.junit.bom))
281
277
testImplementation(" org.junit.jupiter:junit-jupiter" )
278
+ testRuntimeOnly(" org.junit.platform:junit-platform-launcher" )
282
279
283
280
errorprone(libs.errorprone)
284
281
}
0 commit comments