Skip to content

Commit 1a4ee04

Browse files
committed
Polish "automate protobuf generation in tests"
This moves the common proto plugin pieces into a shared groovy plugin script. Also, resolves an unrelated (but blocking) error about the `spring-pulsar-cache-provider` module's `compileJava` task depending on the `formatMain` task.
1 parent ed56a39 commit 1a4ee04

File tree

4 files changed

+33
-41
lines changed

4 files changed

+33
-41
lines changed

buildSrc/src/main/java/org/springframework/pulsar/gradle/JavaConventionsPlugin.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,10 @@ public void apply(Project project) {
114114

115115
private void configureSpringJavaFormat(Project project) {
116116
project.getPlugins().apply(SpringJavaFormatPlugin.class);
117-
project.getTasks().withType(Format.class, (Format) -> Format.setEncoding("UTF-8"));
117+
project.getTasks().withType(Format.class, (format) -> {
118+
format.setEncoding("UTF-8");
119+
project.getTasks().named("compileJava", JavaCompile.class, format::mustRunAfter);
120+
});
118121
project.getPlugins().apply(CheckstylePlugin.class);
119122
CheckstyleExtension checkstyle = project.getExtensions().getByType(CheckstyleExtension.class);
120123
checkstyle.setToolVersion("10.12.4");

gradle/proto-conventions.gradle

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//file:noinspection GroovyUnusedAssignment
2+
3+
tasks.matching { (it.name "extractIncludeTestFixturesProto") }
4+
5+
tasks.matching { (it.name == "extractIncludeTestFixturesProto") }
6+
7+
tasks.matching { (it.name == "extractIncludeTestFixturesProto") }
8+
9+
tasks.named('extractIncludeProto') { enabled = false }
10+
tasks.named('extractIncludeTestProto') { enabled = false }
11+
tasks.matching { (it.name == "extractIncludeTestFixturesProto") }
12+
.configureEach { enabled = false }
13+
14+
tasks.withType(io.spring.javaformat.gradle.tasks.CheckFormat).configureEach { task ->
15+
task.source = project.files(
16+
task.source.filter { file ->
17+
!file.path.contains('build/generated/source/proto')
18+
task.enabled = false
19+
}
20+
)
21+
}
22+
23+
protobuf {
24+
protoc {
25+
artifact = libs.protobuf.protoc.get()
26+
}
27+
}

spring-pulsar-reactive/spring-pulsar-reactive.gradle

+1-19
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,11 @@
1-
import io.spring.javaformat.gradle.tasks.CheckFormat
2-
31
plugins {
42
id 'org.springframework.pulsar.spring-module'
53
alias(libs.plugins.protobuf)
64
}
75

86
description = 'Spring Pulsar Reactive Support'
97

10-
tasks.named('extractIncludeProto') { enabled = false }
11-
tasks.named('extractIncludeTestProto') { enabled = false }
12-
13-
tasks.withType(CheckFormat).configureEach { task ->
14-
task.source = project.files(
15-
task.source.filter { file ->
16-
!file.path.contains('build/generated/source/proto')
17-
task.enabled = false
18-
}
19-
)
20-
}
21-
22-
protobuf {
23-
protoc {
24-
artifact = libs.protobuf.protoc.get()
25-
}
26-
}
8+
apply from: '../gradle/proto-conventions.gradle'
279

2810
dependencies {
2911
api project (':spring-pulsar')

spring-pulsar/spring-pulsar.gradle

+1-21
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import io.spring.javaformat.gradle.tasks.CheckFormat
2-
31
plugins {
42
id 'org.springframework.pulsar.spring-module'
53
id 'java-test-fixtures'
@@ -8,24 +6,7 @@ plugins {
86

97
description = 'Spring Pulsar Core'
108

11-
tasks.named('extractIncludeProto') { enabled = false }
12-
tasks.named('extractIncludeTestProto') { enabled = false }
13-
tasks.named('extractIncludeTestFixturesProto') { enabled = false }
14-
15-
tasks.withType(CheckFormat).configureEach { task ->
16-
task.source = project.files(
17-
task.source.filter { file ->
18-
!file.path.contains('build/generated/source/proto')
19-
task.enabled = false
20-
}
21-
)
22-
}
23-
24-
protobuf {
25-
protoc {
26-
artifact = libs.protobuf.protoc.get()
27-
}
28-
}
9+
apply from: '../gradle/proto-conventions.gradle'
2910

3011
dependencies {
3112
api 'io.micrometer:micrometer-observation'
@@ -78,4 +59,3 @@ dependencies {
7859
// Used by UserRecordDe/serializer in test fixtures
7960
testFixturesApi 'com.fasterxml.jackson.core:jackson-databind'
8061
}
81-

0 commit comments

Comments
 (0)