avro gradle plugin sample usage

Tin H Kyaw picture Tin H Kyaw · Nov 12, 2012 · Viewed 11.7k times · Source

I am trying to use the avro-gradle-plugin on github, but have not gotten any luck getting it to work. Does anyone have any sample code on how they get it to work?

Answer

Tin H Kyaw picture Tin H Kyaw · Nov 13, 2012

I figured out how to do it myself. The following is a snippet that I would like to share for people who might run into the same issues as I did:

apply plugin: 'java'
apply plugin: 'avro-gradle-plugin'

sourceCompatibility = "1.6"
targetCompatibility = "1.6"

buildscript {
  repositories {
    maven { 
      // your maven repo information here
    }
  }
  dependencies {
    classpath 'org.apache.maven:maven-artifact:2.2.1'
    classpath 'org.apache.avro:avro-compiler:1.7.1'
    classpath 'org.apache.avro.gradle:avro-gradle-plugin:1.7.1'
  }
}

compileAvro.source = 'src/main/avro'
compileAvro.destinationDir = file("$buildDir/generated-sources/avro")

sourceSets {
  main {
    java {
      srcDir compileAvro.destinationDir
    }
  }
}

dependencies {
  compileAvro
}