Hi,
I’m using the copy filter feature for the purpose of templating a bunch of apache configuration files. Essentially I have to produce 15 brand variations of apache configurations. The differences between each brand are very subtle and can be mostly achieved by using the filtering feature of the copy task to search and replace properties in sources to produce the unique apache configuration files.
I’ve managed to get this working for one brand but I’m struggling to understand how I can do this for all 15 in one gradle build script. I believe this can be achieved using flavors where each brand is a flavor that produces a unique variation.
All the examples of using flavours I’ve so far found were using the android or naive build plugins, but my build is not an android build, hence why I can’t quite figure out how things tie together. The build script below is what I have got going for one brand thus far. I would love if someone could explain how flavors work and what I would need to do to make the build produce all brand variations.
Many thanks,
apply plugin: ‘distribution’ version = ‘0.0.0-SNAPSHOT’
distributions {
main {
contents {
from { ‘build/apache’ }
into { ‘/etc/apache2/’ }
}
} }
defaultTasks ‘distTar’
def brand = “fooCom” def brandProperties = [
domainName: ‘foo.com’,
brandId: ‘1’,
name: ‘fooCom’ ]
// How do we flavor the buld to produce fooCom and barCom flavours? //def brand = “barCom” //def brandProperties = [ //
domainName: ‘bar.com’, //
brandId: ‘1’, //
name: ‘barCom’ //]
task copyScripts(type: Copy) {
description ‘Copy all source files into build dir filtering and replacing an @xxxx@ tokens’
from(‘src’) {
filter(org.apache.tools.ant.filters.ReplaceTokens, tokens: brandProperties)
exclude { details -> details.file.name.endsWith(’.template’) || details.file.name =~ /^…*.sw.$/ }
exclude ‘brands/**’
}
into(‘build/apache/’) }
task copyModules(type: Copy) {
from(‘modules’) {
rename { String fileName ->
fileName.replaceAll(/2.4-[0-9.]+.so$/, ‘.so’)
}
}
into(‘build/apache/modules’) }
task copyTemplates(dependsOn: copyScripts, type: Copy) {
description ‘Copy all .template source files into build dir passing the file through a SimpleTemplateEngine’
from(‘src’)
into(‘build/apache/’)
include ‘**/*.template’
rename { String fileName ->
fileName.replace(’.template’, ‘’)
}
expand(brandProperties) }
task copyBrandSpecificConfig(dependsOn: copyTemplates, type: Copy) {
from(“src/brands/${brand}”) {
filter(org.apache.tools.ant.filters.ReplaceTokens, tokens: brandProperties)
exclude { details -> details.file.name.endsWith(’.template’) || details.file.name =~ /^…*.sw.$/ }
}
into(‘build/apache’) }
distTar.dependsOn(copyBrandSpecificConfig)