Git Product home page Git Product logo

thrifty-maven-plugin's Introduction

thrifty-maven-plugin

Build Status PRs Welcome Maven Central

Thin wrapper around the thrifty-compiler. This maven plugin generates the placeholder code for a thrift IDL file using the thrifty library.

Advantages of using Thrifty over the regular Thrift distribution for Java code generation:

  • All compilation happens on the JVM, no need to install Thrift binaries.
  • Thrifty generates better java code: immutable objects with builders.
  • Thrifty has a smaller footprint, the generated byte code is perfectly compatible.

Usage

Add the following plugin to the <build> part of your Maven pom.xml file

<plugin>
    <groupId>com.github.timvlaer</groupId>
    <artifactId>thrifty-maven-plugin</artifactId>
    <version>0.8.0</version>
    <configuration>
        <thriftFiles>
            <file>thrift-schema/internal.thrift</file>
        </thriftFiles>
        <enableConvenienceMethods>true</enableConvenienceMethods><!--default is false-->
        <generateGettersInBuilders>false</generateGettersInBuilders><!--default is false-->
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>thrifty-compiler</goal>
            </goals>
        </execution>
    </executions>
</plugin>

The generated code depends on thrifty-runtime, so add the following to your dependency list.

<dependency>
    <groupId>com.microsoft.thrifty</groupId>
    <artifactId>thrifty-runtime</artifactId>
    <version>3.0.0</version>
</dependency>

Java 9 and above

Add the maven.compiler.release property to the pom.xml file. The plugin will pick this up and configure Thrifty accordingly.

<maven.compiler.release>11</maven.compiler.release>

Generated convenience methods

This Maven plugin generates extra methods if you set <enableConvenienceMethods> to true (default is false).

On all classes:

  • public static Builder builder(), as a shortcut to new StructName.Builder()
  • public static Builder builder(StructName prototype), as a shortcut to new StructName.Builder(struct)
  • public Builder toBuilder(), as a shortcut to new StructName.Builder(struct)

On classes that are based on Thrift union types:

  • public String tag() which returns the name of the filled field
  • public Object value() which returns the value of the filled field (untyped)
  • For each union field, a static factory method, e.g. public static UnionName unionValue(String unionValue)

If you set <generateGettersInBuilders> to true, this plugin will generate getter methods on builders. This might ease migration from the default (mutable) thrift generated code. Effective Java doesn't recommend Getters on builders, so the default for this setting is false.

thrifty-maven-plugin's People

Contributors

dependabot[bot] avatar keshan-desilva avatar timvlaer avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

keshan-desilva

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.