Executing a shell script from gradle
suggest changeA shell script is a very versatile way to extend your build to basically anything you can think of.
As an example, this compiles protobuf files and writes the generated Java into the source tree. afterEvaluate runs the script at the end of configuration, before the Java compile tasks:
def compilePb() {
exec {
// NOTICE: gradle will fail if there's an error in the protoc file...
executable "../pbScript.sh"
}
}
project.afterEvaluate {
compilePb()
}
../pbScript.sh is one directory above the build.gradle that runs the task. For a module build file, that is the project root:
#!/usr/bin/env bash
pp=/home/myself/my/proto
/usr/local/bin/protoc -I=$pp \
--java_out=./src/main/java \
--proto_path=$pp \
$pp/my.proto \
--proto_path=$pp \
$pp/my_other.proto
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents