1

I have two gradle modules(A and B). Module B depends on module A.

Module A contains Copy task from relative path:

task copyStrings(type: Copy){
    from '../path/'
    into 'folder'
}

tasks.preBuild.dependsOn('copyStrings')

When I execute ./gradlew assemble from module A it works perfectly.

But when I am assembling module B, gradle can't found such directory, because relative path is made from module B directory.

Is there any way to set working directory for Copy task?

Andrii Abramov
  • 10,019
  • 9
  • 74
  • 96
  • 2
    Could you please try `from project.file('../path/')`? – Opal Dec 16 '16 at 10:49
  • Also, there's no need for `<<`, `task copyStrings(type: Copy) { from '../path/' into 'folder' }` is all you need. [Here](https://github.com/Opalo/stackoverflow/tree/master/41182383) is a small demo. – Opal Dec 16 '16 at 11:16
  • 1
    It is not only not needed, but plainly wrong and probably just an error in the question, because with the `<<` the task will never be executed as it has no inputs defined during configuration phase but only during execution phase which is plainly wrong and will not work in this case. – Vampire Dec 16 '16 at 12:04
  • Yes, @Vampire, you're 100% right! – Opal Dec 16 '16 at 12:08
  • @Opal I have edited the question. This is definitely not a reason of not resolving path – Andrii Abramov Dec 16 '16 at 12:14
  • I don't know the whole setup but it definitely wasn't right. Please let me know if my answer is helpful. – Opal Dec 16 '16 at 12:17

1 Answers1

1

Could you please try:

from project.file('../path/')

Also, there's no need for <<:

task copyStrings(type: Copy) { 
   from '../path/' into 'folder' 
}

is all you need. Here you can find a little demo.

Opal
  • 81,889
  • 28
  • 189
  • 210