Including Generated Code in JAR with Gradle

I wrote a simple gradle task to generate economical 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 great for me. What I want to do is connect it to the build process so that the stubs are included in my JAR file. I am having trouble finding a good example where to do this and where to write files so that they are included in my JAR. What is the best way to do this or a project that has an example?

+4
source share
1 answer

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

 jar { from "$buildDir/thrift-stubs" } 
+12
source

Source: https://habr.com/ru/post/1343984/


All Articles