google / protobuf-gradle-plugin

Protobuf Plugin for Gradle
Other
1.77k stars 273 forks source link

MergeJavaResource fails because of duplicate .proto files #684

Open ADVavvas opened 1 year ago

ADVavvas commented 1 year ago

There are 3 modules in the project: app, app-common, app-native.

At the moment, since app-native requires both Java and C++ compiled protobuf classes it declares 2 dependencies:

implementation project(path: ':app-common') // Java dependencies
protobuf project(path: ':app-common') // .proto files to be recompiled but in C++

This leads to duplicate .proto files when merging:

> A failure occurred while executing com.android.build.gradle.internal.tasks.MergeJavaResWorkAction
  > 2 files found with path 'Foo.proto' from inputs:
     - /Users/..../app-native/build/intermediates/library_java_res/debug/res.jar
     - /Users/.../app-common/build/libs/app-common.jar

Adding packaging options to app-native e.g. resources.excludes.add("*.proto") seems to have no effects. Excluding the .proto from app-common (jar { exclude '**/*.proto') somewhat works for the user defined protos, but still fails with the same error caused bygoogle/protobuf/Foo.proto` instead.

I realise the project configuration might be unconventional but I don't know what an alternative could be, so any help is appreciated.