spock-yh / gradle-avro-plugin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Overview

This is a Gradle plugin to allow easily performing Java code generation for Apache Avro. It supports JSON schema declaration files, JSON protocol declaration files, and Avro IDL files.

Build Status

Usage

Add the following to your build.gradle file. Substitute the desired version based on CHANGES.md.

// Gradle 2.1 and later
plugins {
  id "com.commercehub.gradle.plugin.avro" version "VERSION"
}

// Earlier versions of Gradle
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath "com.commercehub.gradle.plugin:gradle-avro-plugin:VERSION"
    }
}
apply plugin: "com.commercehub.gradle.plugin.avro"

Optionally, configure the string type to charSequence, string (the default), or utf8.

avro {
    stringType = "string"
}

Optionally, you can also configure the output character encoding.

avro {
    encoding = "UTF-8"
}

Additionally, ensure that you have a compile dependency on avro, such as:

repositories {
    jcenter()
}
dependencies {
    compile "org.apache.avro:avro:1.7.6"
}

If you now run gradle build, Java classes will be compiled from Avro files in src/main/avro. Actually, it will attempt to process an "avro" directory in every SourceSet (main, test, etc.)

IntelliJ Integration

The plugin attempts to make IntelliJ play more smoothly with generated sources when using Gradle-generated project files. However, there are still some rough edges. It will work best if you first run gradle build, and after that run gradle idea. If you do it in the other order, IntelliJ may not properly exclude some directories within your build directory.

Alternate Usage

If the defaults used by the plugin don't work for you, you can still use the tasks by themselves. In this case, use the "com.commercehub.gradle.plugin.avro" plugin instead, and create tasks of type GenerateAvroJavaTask and/or GenerateAvroProtocolTask.

Here's a short example of what this might look like:

apply plugin: "java"
apply plugin: "com.commercehub.gradle.plugin.avro-base"

dependencies {
    compile "org.apache.avro:avro:1.7.6"
}

task generateAvro(type: com.commercehub.gradle.plugin.avro.GenerateAvroJavaTask) {
    source("src/avro")
    outputDir = file("dest/avro")
}

compileJava.source(generateAvro.outputs)

About

License:Apache License 2.0


Languages

Language:Java 89.4%Language:Groovy 10.6%