Hi everybody,
I’m facing a problem in my build script and I’m not sure how to handle it:
I have three tasks:
The first task reads a file and reads a build number from it, increments it and saves it for other tasks to use it The second task builds a zip file and uses this variable to name the zip The third task copies the zip and some other stuff to a new destination
ext.release = '1.9'
ext.patch = '1'
ext.destDir = 'build'
// dummy value, actual value will be read from build.properties
ext.build = 'xxx'
ext.tag = 'MyApp_' + release + '.' + patch + '_'
task incrementBuildNumber() {
doLast{
// read line, parse buildnumber, set next number
def path = 'build.properties'
def list = []
File propertyFile = file(path)
// find old number by going through each line
propertyFile.eachLine {line ->
// save previous number, set new number
if(line.startsWith("release.buildnumber=")) {
// set build, 22 is dummy because it does not matter
// where it comes from here
globeBuild = '22'
// set new value
line = "release.buildnumber="+ tag + '22'
}
// save in list
list += line
}
// delete old, create new, put content in file
propertyFile.delete()
propertyFile.createNewFile()
// write new properties back in file from list
list.each{ item -> propertyFile << item+"\n" }
}
}
task packageDM(type:Zip, dependsOn:['incrementBuildNumber']) {
//Should be MyApp_1.9.1_021 but uses MyApp_1.9.1_xxx
baseName = tag + build
from('src/main/db') {
include '**/*'
into('DB/prod')
}
from('.') {
include 'build.properties'
}
}
task copyPackage(type:Copy, dependsOn:['packageDM']) {
// move file to new destination
def dir = destDir
from '.'
into dir
include tag + build + '.zip'
// delete original file
doLast{
file(tag + build + '.zip').delete()
}
}
I would like to parse the number and use it for each other tasks. But the zip and copy task use the variable in the configuration phase but the increment task is called in the execution phase (zip is always called ‘MyApp_1.9.1_xxx’ instead of the real build number from the file) Is it possible to change that, because i don’t want to pass parameters from outside.
Thanks in advance Stefan