Git Product home page Git Product logo

thrift-gradle-plugin's Introduction

Gradle Thrift Plugin

Gradle Thrift Plugin uses thrift compiler to compile Thrift IDL files. This project is forked from jruyi/thrift-gradle-plugin.
It is open-sourced and licensed under Apache License 2.0 by LINE Corporation.

Usage

To use this plugin, add the following to your build script.

plugins {
    id "com.linecorp.thrift-gradle-plugin" version "0.6.1"
}

Or using legacy plugin application.

buildscript {
    repositories {
        maven {
            url = uri("https://plugins.gradle.org/m2/")
        }
    }
    dependencies {
        classpath("com.linecorp.thrift-gradle-plugin:com.linecorp.thrift-gradle-plugin.gradle.plugin:0.6.1")
    }
}

apply plugin: "com.linecorp.thrift-gradle-plugin"

Example

See the examples/java-project directory for a very simple example.

Implicitly Applied Plugins

None.

Tasks

The Thrift plugin adds compileThrift task which compiles Thrift IDL files using thrift compiler. You can use thrift extension to configure the added compileThrift task.

Table-1 Properties of compileThrift Extension
Extension property Type Default value of compileThrift added by plugin
thriftExecutable String thrift
sourceDir File projectDir/src/main/thrift
sourceItems Object... projectDir/src/main/thrift
outputDir File buildDir/generated-sources/thrift
includeDirs Set []
generators Map<String, String> ['java':''] if autoDetectPlugin is true and JavaPlugin is applied, otherwise []
nowarn boolean false
strict boolean false
verbose boolean false
recurse boolean false
debug boolean false
createGenFolder boolean true
autoDetectPlugin boolean true

If createGenFolder is set to false, no gen-* folder will be created.

sourceDir is only used for backward compatibility

sourceItems are a set of sources, which will be used for generating java files from thrift. A source can either be a path specified as a string or a file. In case a source is a relative path the source will be relative to srcDir. In case a source is a directory, the directory will be scanned recursively for *.thrift files and used.

When autoDetectPlugin is true, generator 'java' will be created and the generated java code will be added to Java source automatically. And the task will be added to compileJava task's dependency. We can disable this by setting autoDetectPlugin to false.

Example
compileThrift {
    recurse true

    generator 'html'
    generator 'java', 'private-members'
}

Creating a custom task by extending CompileThrift

You can create a custom task by extending CompileThrift with the following properties. Plugin will set default values to the properties listed in Table-3.

Table-2 Task properties of CompileThrift
Task property Type
thriftExecutable String
sourceItems Object...
outputDir File
includeDirs Set
generators Map<String, String>
nowarn boolean
strict boolean
verbose boolean
recurse boolean
debug boolean
createGenFolder boolean
Table-3 Default value of task properties set by plugin
Task property Type Default value of CompileThrift set by plugin
thriftExecutable String thrift
nowarn boolean false
strict boolean false
verbose boolean false
recurse boolean false
debug boolean false
createGenFolder boolean true
Example

Below example is creating a custom task by extending CompileThrift and add it to compileJava task's dependency.

tasks.register("customCompileThrift", com.linecorp.thrift.plugin.CompileThrift) {
    thriftExecutable = "../../lib/thrift/0.17.0/thrift.${osdetector.classifier}"
    sourceItems.from(layout.projectDirectory.dir("src/main/thrift"))
    outputDir.set(layout.buildDirectory.dir("gen-gen-src"))
    generators.put('java', 'private-members')
}

tasks.named("compileJava") {
    dependsOn("customCompileThrift")
}

thrift-gradle-plugin's People

Contributors

agemocui avatar haocheng avatar k-mack avatar kojilin avatar mat013 avatar matsumana avatar szarnyasg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

thrift-gradle-plugin's Issues

Add Github PR template

Add Github PR template so that contributors can easily know what's required for creating PR

Provide an example of configuration with kotlin

The gradle configuration with kotlin is relatively less straightforward than the one with groovy.

I believe that it would be helpful to include an example of configuration with the kotlin.

I could make a pull request if you think that it's a good idea.

An example of a working (kotlin) configuration is :

tasks {	
	compileThrift{
		thriftExecutable = "../thrift/libs/0.17.0/thrift.${osdetector.classifier}"
		sourceItems.from(project.layout.files("../thrift/src"))
	}
}

Add Checkstyle config

Add Checkstyle config so that we can make sure all the codes following the same style

Using Java to write plugin

I think we can migrate from Groovy to Java.

  1. It can help us checking the code at compile time
  2. Seems like using kotlin to write the plugin may cause dependency version issues? Not sure if the problem still exists, but you might want to use Java before checking.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.