Comments (4)
I am not sure that I agree with this interpretation. In your build you have 2 proto sources, one, living in the source-tree, thus under src/test/proto and another declared as a dependency. The problem being is that you are defining a proto dependency of a main proto as a test dependency, whereas, because the test configuration depeneds on main, all your classes in main are already available to test, thus the classes generated from the messages.proto. Any protos you declare as dependencies for the configuration, get extracted into the build/extracted-protos/ directory, as they should.
Also, according to the recommendations, it is a bad practice to bundle pre-compiled proto generated java classes and distribute them as dependencies, as they depend on a fixed and exact version of Google's protobuf-lib-java and will cause far more conflicts if mismatched. The recommended approach is to always generate the java stubs for protos directly inside the build, and that is why the plugin supports ability to define tar/zip/etc dependencies for proto archived artifacts to be used/shared between different projects.
from gradle-plugin-protobuf.
because the test configuration depeneds on main, all your classes in main are already available to test
Yes, but the protos aren't. If I skip testProtobuf fileTree("src/main/proto")
, I get
messages.proto: File not found.
messages_test.proto: Import "messages.proto" was not found or had errors.
(I know this is rather artificial, in my real project both main and test depend on the same library proto, but the result is the same: I need the testProtobuf import and also have the proto in the main configuration)
Also, according to the recommendations, it is a bad practice to bundle pre-compiled proto generated java classes and distribute them as dependencies, as they depend on a fixed and exact version of Google's protobuf-lib-java and will cause far more conflicts if mismatched.
I was not aware of this recommendation, following that might be part of the solution - it doesn't solve the issue of protos in both main and test, though.
If I may ask, does that mean that libraries should never package the compiled protos? Doesn't that mean that using protobuf can never be transparent to a consuming project?
Maybe a useful proposal would be to do the following change:
- get rid of the testProtobuf dependency (in my project)
- add
-Isrc/main/proto -Ibuild/extracted-protos/main
togenerateTestProto
, but don't compile the files in these directories
What do you think?
from gradle-plugin-protobuf.
To answer the question of packaging - YES, protos are like old CORBA idl files, you don't want to precompile and redistribute them, as they are ALWAYS subject to change, that code is not real, it is a generated mapping on top of some serialization. The compatibility guaranteed is the wire-format compatibility, not the java code generation (it actually changes with every version of protoc, even the patched ones). That is one of the reasons why in protoc 2.3 Google has added the code generation plugin support to protoc, in order to allow people to inject bits and pieces of custom, explicit (real) code into the generated one.
So you can using the include directive to just include files you don't care about compiling from elsewhere... That can be done by setting the include on the ProtobufCompile - https://github.com/aantono/gradle-plugin-protobuf/blob/master/src/main/groovy/ws/antonov/gradle/plugins/protobuf/ProtobufCompile.groovy#L21
from gradle-plugin-protobuf.
Thanks for the response, adding the includes worked as I expected, so that's definitely a workaround for now. I did it in the least flexible way possible - only for the test configuration, and only with default paths, but that's the code if anybody needs it for their project:
generateTestProto.include("src/main/proto")
generateTestProto.include("build/extracted-protos/main")
from gradle-plugin-protobuf.
Related Issues (15)
- incompatible with the android plugin HOT 3
- Specify repository as a dependency HOT 3
- Update methods to be deprecated in Gradle 2.0 HOT 4
- How to generate output?
- Add support for the other built-in code generators HOT 1
- Adding directory to protoc's include path HOT 1
- Plugin should have an simpler name HOT 1
- Prevent copying protos to extractedProtosDir
- Plugin prints "error" message when running Gradle 2.1 HOT 1
- protobufCodeGenPlugins strips everything after colon in Windows filenames
- Assumption of 'proto' subdir is too restrictive
- proto import statement from Android project to Android project broken? HOT 1
- Specify directory or list of files as a dependency HOT 9
- Unable to build proto in generateProto task HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gradle-plugin-protobuf.