Closed matty closed 2 years ago
Is it what you are saying?
src/main/proto/proto1/foo.proto
src/main/proto/proto1/bar.proto: import "proto2/foo.proto"
src/main/proto/proto2/foo.proto
src/main/proto/proto2/baz.proto: import "proto1/foo.proto"
Can you post the exact error message?
More like: (assuming the import imports the file in the same directory)
src/main/proto/proto1/foo.proto
src/main/proto/proto1/bar.proto: import "foo.proto"
src/main/proto/proto2/foo.proto
src/main/proto/proto2/bar.proto: import "foo.proto"
The error produced will be: "proto1/foo.proto Input is shadowed in the --proto_path by proto2/foo.proto"
I assume because the files are the same name, but it would be nice that you can generate multiple protobufs in one task.
What does your sourceSets block look like?
sourceSets {
main {
proto {
srcDir 'src/main/protobufs/protobufs1'
srcDir 'src/main/protobufs/protobufs2'
}
}
}
I have also tried using the default folder "protobuf". The issue I think is if you have imports with the same names there are conflict errors, maybe if there are multiple source set folders provided have them run separately?
Try removing the whole sourceSets
block (thus using the default src/main/proto
), and include the path in the imports
statement:
src/main/proto/proto1/foo.proto
src/main/proto/proto1/bar.proto: import "proto1/foo.proto"
src/main/proto/proto2/foo.proto
src/main/proto/proto2/bar.proto: import "proto2/foo.proto"
I can give that a try but I did try something like that already, just in a different folder and one folder specified in the sourcesets. I believe its more an issue with files being the same name and being referenced twice although they actually have differences.
@matty do you still have the issue? It would be useful if you can provide me a demonstration project.
I have the same issue. I use 2 definitions and the proto files have the same names like the example above. Does anyone have a solution except renaming of the protofiles?
Is this issue still open, what is the recommended work around?
I am receiving the same error, Input is shadowed in the --proto_path...
I have a single proto file importing google/protobuf/any.proto
.
My build.gradle
file is very simple and is based off of examples in this repository.
apply plugin: 'java'
apply plugin: 'com.google.protobuf'
apply plugin: 'idea'
buildscript{
repositories{
gradlePluginPortal()
}
dependencies {
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.19'
}
}
gradle.startParameter.showStacktrace = org.gradle.api.logging.configuration.ShowStacktrace.ALWAYS
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
implementation 'com.google.protobuf:protobuf-java:3.21.4'
protobuf files("src/main/proto/")
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
}
protobuf {
protoc {
artifact = 'com.google.protobuf:protoc:3.21.4'
}
}
test {
useJUnitPlatform()
You should never have two imports that match exactly but are for different files. The file name can match, but the import path must be different. Proto imports should be globally unique (using folders for namespacing), just like proto message names (using packages for namespacing). I'm simply repeating the suggesting earlier: https://github.com/google/protobuf-gradle-plugin/issues/69#issuecomment-213007697
For well-known protos like google/protobuf/any.proto
, this issue is unrelated.
When you have multiple protobufs inside the proto folder for example, proto/proto1 & proto/proto2 but inside proto1 you have an proto file with an import that imports a file inside proto1 and in proto2 you have an proto file with na import that imports a file inside proto2 and both import files are the same file name as the others.
This causes an issue with the import already being imported from the previous folder. Is there a way to run the protobuf gradle task multiple times whilst pointing to different folders?