Question

I wrote a simple gradle task to generate thrift files:

task generateThrift << {
  thriftFiles = fileTree(dir: 'src/main/thrift').matching { include '**/*.thrift' }
  exec {
    executable = 'thrift'
    args = ['--gen', 'java:hashcode', '-o', '/tmp', thriftFiles.collect { relativePath(it) }.join(",") ]
  }
}

This works fine for me. What I want to do is hook it into the build process so the stubs are including in my JAR file. I'm having trouble finding a good example of where to hook this in, and where to write the files out to so that they are included in my JAR. What's the best way to do this or a project that has an example?

Was it helpful?

Solution

I suggest to write the files to a subdirectory of the build output directory, say thrift-stubs. Then you can include them in the Jar like so:

jar {
  from "$buildDir/thrift-stubs"
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top