Skip to content

Commit 72b09f7

Browse files
committed
Add check for protoc version to build.gradle
1 parent 182a35f commit 72b09f7

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

java/client/build.gradle

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,29 @@ dependencies {
3131
testImplementation group: 'org.mockito', name: 'mockito-junit-jupiter', version: '3.12.4'
3232
}
3333

34+
ext {
35+
checkProtocVersion = { String output ->
36+
// Line in format like: libprotoc 26.1
37+
int majorVersion = java.lang.Integer.parseInt(output.split(" ")[1].split("\\.")[0].trim());
38+
int minorVersion = java.lang.Integer.parseInt(output.split(" ")[1].split("\\.")[1].trim());
39+
if (majorVersion < 26 || (majorVersion == 26 && minorVersion < 1)) {
40+
throw new GradleException("Use Protoc version 26.1 or later");
41+
}
42+
return output.split(" ")[1]
43+
}
44+
}
45+
3446
tasks.register('protobuf', Exec) {
3547
doFirst {
48+
new ByteArrayOutputStream().withStream { os ->
49+
exec {
50+
commandLine 'protoc', '--version'
51+
workingDir Paths.get(project.rootDir.path, '..').toFile()
52+
standardOutput = os
53+
}
54+
checkProtocVersion(os.toString())
55+
}
56+
3657
project.mkdir(Paths.get(project.projectDir.path, 'src/main/java/glide/models/protobuf').toString())
3758
}
3859
commandLine 'protoc',

0 commit comments

Comments
 (0)