What causes copy task to fail when using variables?

I am a little bit mistified on the behavior of a file copy. Folder structure exists and works for normal file manipulations in my shell.

I have the following Gradle code not working, despite the fact that I can log those variables out and get the perfect absolute path in the console.

task copyAndRename(type: Copy, dependsOn: assemble){
     def sourcedir = workspace + /'relative/source/dir/to/lib'
   def destdir = workspace + '/relative/dest/dir/of/lib'
     from (sourcedir)
   into destdir

I tried variations without success, such as

from ('${workspace}/relative/source/dir/to/lib')
into '${workspace}/relative/dest/dir/of/lib'

The only way this is working is when I put the absolute path as a String parameter to from and into, as in /var/tmp or so.

from ('from/root/with/full/source/path')
    into 'from/root/with/full/destination/path'

This is clearly not ideal and I am sure there is a way, but what am I missing here?

To do variable replacement in a string in Groovy you must use a ‘GString’ literal, which is denoted with double-quote (’"’) instead of the regular single-quote. For example:

from “${workspace}/relate/source/dir/to/lib”

See the Groovy documentation for more information.

Thank you so much. So simple and yet it was ruining my day with an “impossible to understand” behavior.