Search code examples
groovygradlethrift

Gradle Thrift Plugin by Example


Please note: Although this question specifically calls out the Gradle Thrift plugin, I believe this is just a general Gradle question that any battle-weary Gradle veteran could help me with.


I am new to Apache Thrift and only quasi-familiar with Gradle (2.4.x). I am trying to get the Gradle Thrift plugin to work and am encountering a few issues that are likely just gaps in my Gradle knowledge.

Here is my sample project: thrifty

If you clone it and run ./gradlew compileThrift, you'll see it does exactly what the Gradle Thrift README says it will do. It generates source under build/generated-sources/thrift/*.

I would like to compile and build this source. For the Java source that it generates, I'd like to produce a JAR library...so what's the best way to do this? Should I copy, say, build/generated-sources/thrift/gen-java/* to src/main/java, and then run build?


Solution

  • so, you should just be able to add the following to your build script

    compileThrift {
        outputDir = file('src/generated/thrift')
    }
    
    sourceSets {
        main.java.srcDirs += 'src/generated/thrift/gen-java'
    }
    

    so the thrift plugin will generate into a folder under src (I just prefer this, to source code being in build)

    and then you can add these sources to the directories the java plugin checks

    no idea about your extra python question