Skip to content

Instantly share code, notes, and snippets.

@ysb33r
Last active February 28, 2016 21:57
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Using a Gradle Task as a data-driven file generator
// Uses a single Groovy template and multiple sets of text input files.
// It generates a set of Groovy source files using the content of the text input files to set tokens within the
// template file.
task generateGroovySources( type : Copy ) {
from 'examples', {
include '*.txt'
}
into "${buildDir}/generated-src"
eachFile { fcd ->
String sourceName = fcd.sourceName.replaceAll( /\.txt$/, '')
String content = fcd.file.text
fcd.filter {null}
fcd.filter ConcatFilter, append : project.file('src/templates/my.template')
fcd.filter ReplaceTokens, tokens : [
token1 : content,
token2 : sourceName
]
}
rename ~/\.txt$/, '.groovy'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment