使用 Gradle 将生成的代码包含在 JAR 中
我编写了一个简单的 gradle 任务来生成 thrift 文件:
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(",") ]
}
}
这对我来说效果很好。我想要做的是将其挂接到构建过程中,以便存根包含在我的 JAR 文件中。我很难找到一个很好的例子来说明在哪里挂接它,以及在哪里将文件写出以便它们包含在我的 JAR 中。执行此操作的最佳方法是什么或有示例的项目?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议将文件写入构建输出目录的子目录,例如 thrift-stubs 。然后你可以将它们包含在 Jar 中,如下所示:
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: