4

I have the following task to copy files from my android projects resources files to a different path that is accessible by a ClassLoader instance in a unit test.

task copyResDirectoryToClasses(type: Copy){
    println 'COPYINGCOPYINGCOPYING!!!!!!!!!!!!!!!!!!!!'
    println "$projectDir/src/test/java/com/textmeinc/topmeup/resources/"
    println "$buildDir/intermediates/classes/test/staging/debug/"

    from "$projectDir/src/test/java/com/textmeinc/topmeup/resources/"
    into  "$buildDir/intermediates/classes/test/staging/debug/"
}

assembleDebug.dependsOn(copyResDirectoryToClasses)

I see the task run in my gradle console.

Parallel execution with configuration on demand is an incubating feature.
COPYINGCOPYINGCOPYING!!!!!!!!!!!!!!!!!!!!
/Users/tylerpfaff/Documents/Development/topmeup-android/app/src/test/java/com/textmeinc/topmeup/resources/
/Users/tylerpfaff/Documents/Development/topmeup-android/app/build/intermediates/classes/test/staging/debug/

However, no files are transferred. If I manually move them in the terminal, my tests run fine with my mock.json file. Why isn't the copy working?

This is the command I used to copy the file manually.

cp /Users/tylerpfaff/Documents/Development/topmeup-android/app/src/test/java/com/textmeinc/topmeup/resources/mock.json /Users/tylerpfaff/Documents/Development/topmeup-android/app/build/intermediates/classes/test/staging/debug/
Tyler Pfaff
  • 4,900
  • 9
  • 47
  • 62

2 Answers2

4

I think there's a bug in the plugin. I just ran into this myself. Getting the task to run as a "dependsOn" fails. But if I open the Gradle tab in Android Studio and run the task manually from there, then files are copied. Same goes for command line gradlew :subproject:copytask. I'm going to try to replicate this in an independent project and if I can, i'll submit a bug report for it (and put the link here). In the meantime, manually running that gradle task is my only solution.

JCricket
  • 1,318
  • 2
  • 17
  • 34
  • Thanks for your research! This is incredibly annoying. – Tyler Pfaff May 25 '16 at 17:05
  • do you have a bug report for this? – desgraci Aug 13 '20 at 12:28
  • 1
    @desgraci negative, it's been a while, but from my recollection, I was unable to reproduce that in a standalone project for documentation purposes. I want to say that it did eventually get resolved in a future update, but again a while ago, so I can verify for sure when. – JCricket Aug 13 '20 at 17:14
0

The examples at the top of this documentation page use paths that are relative to projectDir

Try replacing your from and into paths with:

from 'app/src/test/java/com/textmeinc/topmeup/resources'
into 'build/intermediates/classes/test/staging/debug'
RaGe
  • 22,696
  • 11
  • 72
  • 104