Created
May 17, 2014 03:25
-
-
Save granthenke/e4e29b5f67ee02a2dd51 to your computer and use it in GitHub Desktop.
A drop in script to add simple and configurable Avro file compilation support
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A drop in script to add simple and configurable Avro file compilation support | |
buildscript { | |
repositories { | |
mavenCentral() | |
mavenLocal() | |
} | |
dependencies { | |
classpath([ | |
"org.apache.avro:avro-tools:1.7.4" | |
]) | |
} | |
} | |
import org.apache.avro.tool.SpecificCompilerTool | |
def AvroSource = file("src/main/resources/avro") | |
def AvroDest = file("src/main/avro") | |
sourceSets { | |
main { | |
java { | |
srcDir AvroDest | |
} | |
} | |
} | |
task cleanAvro(type: Delete) { | |
delete fileTree(dir: AvroDest) | |
} | |
task compileAvro() { | |
doLast { | |
// The SpecificCompilerTool writes to System.err so we need to redirect it temporarily | |
def oldErrStream = System.err | |
def tempErrStream = new ByteArrayOutputStream() | |
System.setErr(new PrintStream(tempErrStream)) // Catch System.err output from tool | |
// Compile schemas //TODO(GH): Add AVDL support | |
def args = ["-string", "schema", AvroSource.path, AvroDest.path].asList() //Remove -string to use utf8 | |
new SpecificCompilerTool().run(null, null, null, args) | |
// Reset System.err to old stream | |
System.setErr(oldErrStream) | |
logger.info(new String(tempErrStream.toByteArray())) | |
} | |
} | |
compileJava.dependsOn compileAvro |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apply plugin: "java" | |
apply from: "$rootDir/path/to/avro.gradle" // just drop it in you build file (must have java plugin) | |
// build stuff here... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment