8

我写了一个简单的 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 中。执行此操作或有示例的项目的最佳方法是什么?

4

1 回答 1

19

我建议将文件写入构建输出目录的子目录,例如thrift-stubs. 然后你可以像这样将它们包含在 Jar 中:

jar {
  from "$buildDir/thrift-stubs"
}
于 2011-03-16T22:23:38.827 回答