-1

I have added the following task and its execution schedule to build.gradle:

task copyDbFile (type: Copy)

copyDbFile {
    description = 'Copies the relevant db file to assets folder'
    from 'store'
    into 'assets'
    include '**/Test.txt'
}

preBuild {}.dependsOn copyDbFile
preBuild {}.mustRunAfter copyDbFile

I do not get any error but the Test.txt file does not get copied to assets folder.

I see that the task is called/executed in the gradle console:

:clean
:app:clean
:app:copyDbFile UP-TO-DATE
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
...
...
...

But the file does not get copied. I do not get any error. Have never written a gradle task before and am suspecting there is some syntax error or I missed something. But since I do not see any error i am unable to figure out.

What do you think is going wrong in the above because of which the file does not get copied to the destination folder?

The assets and store folders are both at same level under app directory.

Viral Patel
  • 32,418
  • 18
  • 82
  • 110
  • Hmm, I haven't seen anyone do task closure separately from task definition like you did.. don't know if that is causing your issue, but could you try a more standard form? See here for example: https://docs.gradle.org/current/dsl/org.gradle.api.tasks.Copy.html – RaGe Mar 17 '16 at 17:44
  • Thanks! but i did not understand. This is the first time me writing a gradle task hence this silly question: What did you mean by separate task closure? – Viral Patel Mar 17 '16 at 17:48
  • posted a quick answer below. let me know if that works for you. – RaGe Mar 17 '16 at 17:50

1 Answers1

1

Thanks to RaGe's tips which helped me how to debug and helped me figure out that the actual problem was just that path was wrong and sice it was not finding any source file it was skipping the task.

I changed the paths in the task as follows and it worked:

task copyDbFile (type: Copy)

copyDbFile {
    description = 'Copies the relevant db file to assets folder'
    from 'src/main/store'
    into 'src/main/assets'
    include '**/*.txt'
}
Viral Patel
  • 32,418
  • 18
  • 82
  • 110