Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify directory or list of files as a dependency #7

Closed
novabyte opened this issue Jan 9, 2013 · 9 comments
Closed

Specify directory or list of files as a dependency #7

novabyte opened this issue Jan 9, 2013 · 9 comments

Comments

@novabyte
Copy link

novabyte commented Jan 9, 2013

Is it possible to specify fileTree(...) or files(...) to list dependencies?

Something like this:

dependencies {
    protobuf fileTree(dir: 'deps/some_project/src/', include: '**/*.proto')
    protobuf files('deps/some_project/src/**/*.proto')
}
@novabyte
Copy link
Author

For anyone that stumbles upon this issue. A suboptimal workaround that I'm using at the moment is as follows:

depedencies {
    protobuf files("$buildDir/distributions/some_project_pb.zip")
}

task protobufZip(type: Zip) {
    archiveName = 'some_project_pb.zip'
    from "$projectDir/deps/some_project/src"
    include '**/*.proto'
}
extractProto.dependsOn protobufZip

Essentially the above code introduces a task that runs before the extractProto task which zips up the Protocol Buffer definition files in the git submodule dependency that I have on another project. The extractProto task then unzips the files and the generateProto task calls the protoc compiler.

This code moves backwards to go forwards... by zipping up code so that it can then be unzipped by this plugin. If I get some time I'll work on submitting a pull request for this issue but I'm not likely to have time at all soon.

@aantono
Copy link
Owner

aantono commented Jan 13, 2013

Why not just put the files into your ${projectDir}/src/main/proto directory? The plugin will take all the *.proto files from there and run protoc against them.

@novabyte
Copy link
Author

Well, let's say that I'm including (for example) this project as a submodule in my Git project:

https://github.com/basho/riak_pb

That project has three Protobuf definition files (at the moment, this could change at any moment...): riak.proto, riak_kv.proto and riak_search.proto. The application I'm writing only cares about two of those files. I think it's reasonable to assume that it should be possible to at least do something like this in the dependency closure:

dependencies {
    protobuf files('deps/riak_pb/src/riak.proto', 'deps/riak_pb/src/riak_kv.proto')
}

At the moment I'm actually using a modified version of the Zip task I pasted above to zip only the two files.

@novabyte
Copy link
Author

Essentially what I'm hoping for is the inclusion of more fine-grained control over which Protobuf definition files are compiled to Java code without the need to Zip and Unzip a collection of .proto files.

Let me know if the use case (motivation) for this feature request needs more discussion. Cheers.

aantono added a commit that referenced this issue Jan 17, 2013
@aantono
Copy link
Owner

aantono commented Jan 17, 2013

Chris, I've taken a stab at implementing the functionality you've described. Please let me know if this is how you wanted it to work.

Thanks,
Alex

@novabyte
Copy link
Author

novabyte commented Feb 9, 2013

Hey Alex,

Thanks for the feature enhancement, that works for me! :)

Cheers,

Chris

@tinhkyaw
Copy link

Hi Alex,

This is a very useful update. Can you please upload the jar to Maven Central as well?

Also, is there any plan to support wildcards (like *.proto) in the files definition?

Thank You,

Tin

@aantono
Copy link
Owner

aantono commented Feb 14, 2013

Hello Tin,

I am working on cutting the final release of the new version sometime by the end of this month. (Want to make sure that Issue 8 gets resolved). As for the wildcards, you can use any standard Gradle FileCollection generating function (such as files, fileTree, etc), so you should be able to use http://www.gradle.org/docs/current/javadoc/org/gradle/api/Project.html#fileTree(java.util.Map) with something like this: protobuf fileTree(dir: 'protos', include: '*.proto')
Here is the documentation reference - http://www.gradle.org/docs/current/userguide/dependency_management.html#sub:file_dependencies

@tinhkyaw
Copy link

Thank you very much for the detailed response, Alex. I tried and it works for me now. Looking forward to your next release :-)..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants