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?
To add a dependency to your project, specify a dependency configuration such as implementation in the dependencies block of your module's build.gradle file.
Create an executable JAR file gradle file to open it in the editor. in the editor to load the changes to your project. In the Gradle tool window, open the project's node, then the Tasks node and double-click the build task to run it. IntelliJ IDEA creates the build directory that contains our JAR file.
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"
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With