Copy and replacing is saying UP-TO-DATE

I am trying to copy a folder, replace a line in specific file by using this code:

project(':app') {
  task copyAppForVersionUpdate(type: Copy) {
      includeEmptyDirs = true

      from rootProject.file('app/bin/')
      into rootProject.file(dist_dir + 'app')
  }

  task updateAppVersion(type: Copy, dependsOn: copyAppForVersionUpdate){
    from rootProject.file('app/bin/index.php')
    into rootProject.file(dist_dir + 'app/')

    println "Going to update web app version in app/index.php now:"
    filter{
        String line -> line.replaceAll('\\$APP_VERSION = APP_VERSION;',
                '\\$APP_VERSION = "'+ app_version +'";')
    }
  }
}

But running app:updateAppVersion always say UP-TO-DATE. It does copy the app folder from to dist_dir but doesn’t replace and update index.php in this task. Can any one review and let me know what I am doing wrong here? Thanks

If you want app_version to be considered in the task’s UP-TO-DATE checking, you’ll need to configure it as a task input

task updateAppVersion(type: Copy, dependsOn: copyAppForVersionUpdate){
   inputs.property('appVersion', app_version)
   ...
}
1 Like