Closed aogail closed 13 years ago
How is this different in behavior from just adding more directories to the srcDirs from build.gradle (something like: project.tasks['generateProto'].getDefaultSource().srcDir "/some/other/directory/in/addition/to/src/main/proto")?
protoc generates (compiles) all the .proto files that it finds in the -I directories, so there is no such thing as "include a directory but don't use it's content for compilation"
Hm, that's not the behavior I see. When I tell protoc to compile a single proto file that uses types from another proto file, protoc only generates code for uses_common_types.proto:
protoc -I/location/of/common/types uses_common_types.proto
OTOH, if I include the proto files from /location/of/common/types, like adding a srcDir does, protoc generates source for all of them (which is undesirable in my case).
protoc -I/location/of/common/types uses_common_types.proto /location/of/common/types/*.proto
Ok, I think I understand what you are trying to do. Just out of curiosity, if you are using some files for "include" only, when you compile the generated proto sources, where do the references to the files that were used from "include" directories come from? Do you already have them precompiled and pull them as a library?
Yes, that's it.
Do you, by any chance, have an example of a build.gradle file where you would be configuring the "include" directories, so that I can update the README to reflect it as well as make a test for it in the testProject?
I don't have a public project to point to, but here are the essential parts. It's a multi-project build with:
apply plugin: 'ws.antonov.gradle.plugins.protobuf'
configurations {
idl {}
}
dependencies {
idl(group: 'com.foo', name: 'idl', version: '1.0.+')
}
task extractProtos(type:Copy) {
description = 'Copies protobuf IDL files to a location where protoc can read them'
configurations.idl.files.each {File file ->
from(tarTree(file)) {
eachFile {it.path = it.name}
}
}
into "${project.buildDir}/protos"
includeEmptyDirs = false
}
generateProto {
dependsOn(extractProtos)
defaultSource.srcDirs = [extractProtos.destinationDir]
}
apply plugin: 'ws.antonov.gradle.plugins.protobuf'
dependencies {
// other deps ...
compile project(':common-idl')
}
generateProto {
dependsOn project(':common-idl').extractProtos
include project(':common-idl').extractProtos.destinationDir
}
Cool, thanks for the info, will update the wiki with the example. Don't know if you saw, but I've also added support for providing the protobuf tar file as a source of protos instead/in addition of a src directory, so that it can be used as a publishable artifact that would be consumed by your build. To use that just add 'protobuf (group,name,version) into your dependencies list and the plugin will handle it out of the box, automatically extracting the tar.gz into a build/downloaded-protos directory and using it as a source.
Great! When I posted the example I was thinking to myself that it would be nice for the plugin to handle protobuf artifacts automatically. :)
Oh, cool, great minds think alike... :) Can you give it a try to see if this would provide a good alternative to "extractProtos" that you are doing in your example, before I release the 0.5?
I gave it a try. It won't work as-is for my situation:
Once my gradle pull request is integrated I'll see about submitting a patch to your plugin to enable both use cases.
Made it so that extra include directories can be added for protoc, without including their contents to be compiled.