Extending CompilerConfig: InvalidProtocolBufferException "cannot find field"
RdeWilde opened this issue · comments
I try to extend the CompilerConfig
with the ProtobufMessages
as provided in a PR here (https://github.com/marcoferrer/kroto-plus/pull/13/files).
I migrated all the code, but I can't seem to solve this error when I run generateProto
on my sample project app
:
Caused by: com.google.protobuf.InvalidProtocolBufferException:
Cannot find field: mpProtobufMessages in message krotoplus.compiler.CompilerConfig
I do have this field in my config.proto
:
// Configuration entries for the 'Multi-Platform Protobuf Messages' code generator.
repeated MpProtobufMessagesGenOptions mp_protobuf_messages = 27;
Also this field is present in CompilerConfig.java
:
public static final int MP_PROTOBUF_MESSAGES_FIELD_NUMBER = 27;
private java.util.List<com.github.marcoferrer.krotoplus.config.MpProtobufMessagesGenOptions> mpProtobufMessages_;
And it is also in the CompilerConfig initialization
case 218: {
if (!((mutable_bitField0_ & 0x00000080) == 0x00000080)) {
mpProtobufMessages_ = new java.util.ArrayList<com.github.marcoferrer.krotoplus.config.MpProtobufMessagesGenOptions>();
mutable_bitField0_ |= 0x00000080;
}
mpProtobufMessages_.add(
input.readMessage(com.github.marcoferrer.krotoplus.config.MpProtobufMessagesGenOptions.parser(), extensionRegistry));
break;
}
In krotoPlusConfig.yaml:
mpProtobufMessages:
- filter:
excludePath:
- google/*
Complete error message from the sample project:
Execution failed for task ':generateProto'.
> protoc: stdout: . stderr: Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
Caused by: com.google.protobuf.InvalidProtocolBufferException: Cannot find field: mpProtobufMessages in message krotoplus.compiler.CompilerConfig
at com.google.protobuf.util.JsonFormat$ParserImpl.mergeMessage(JsonFormat.java:1348)
at com.google.protobuf.util.JsonFormat$ParserImpl.merge(JsonFormat.java:1308)
at com.google.protobuf.util.JsonFormat$ParserImpl.merge(JsonFormat.java:1190)
at com.google.protobuf.util.JsonFormat$Parser.merge(JsonFormat.java:370)
at com.github.marcoferrer.krotoplus.generators.GeneratorContextKt.getCompilerConfig(GeneratorContext.kt:61)
at com.github.marcoferrer.krotoplus.generators.GeneratorContext.<init>(GeneratorContext.kt:36)
at com.github.marcoferrer.krotoplus.generators.GeneratorKt$contextInstance$2.invoke(Generator.kt:75)
at com.github.marcoferrer.krotoplus.generators.GeneratorKt$contextInstance$2.invoke(Generator.kt)
at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
at com.github.marcoferrer.krotoplus.generators.GeneratorKt.getContextInstance(Generator.kt)
at com.github.marcoferrer.krotoplus.generators.GeneratorKt.initializeContext(Generator.kt:61)
at com.github.marcoferrer.krotoplus.generators.GeneratorKt.initializeContext$default(Generator.kt:59)
at com.github.marcoferrer.krotoplus.KrotoPlusProtoCMain.main(KrotoPlusProtoCMain.kt:32)
... 8 more
--krotoPlus_out: protoc-gen-krotoPlus: Plugin failed with status code 1.
I am unsure what else I could be doing wrong?
Hopefully someone can help me out, been stuck on this wayyy too long.
Looking at the example project I think it might be having issues pulling the snapshot from your local kroto branch.
You can try setting the plugin using an absolute path to your local kroto plugin build.
configure<ProtobufConfigurator> {
generatedFilesBaseDir = "$projectDir/src/"
protoc {
artifact = "com.google.protobuf:protoc:3.9.0"
}
plugins {
id("krotoPlus") {
path = "path/to/protoc-gen-kroto-plus/build/libs/protoc-gen-kroto-plus-0.4.1-SNAPSHOT-jvm8.jar"
}
}
...
}
That actualy did work \o/ Thank you very much!
Shouldn't the composite build have replaced it with the local version?
Not entirely sure how composite builds would work with local development. I think the previous config might have worked if the generateProto task depended on publishing to mavenLocal.
I understand, thanks again for helping me out, this is solved for now 👍
The code generation now works thru Kotlinpoet. Had to apply a few small fixes, but now it's awesome.