How to copy and rename a single file?


(ian.durkan) #1

Here’s the task I’m trying to use to copy a single file to a differently-named file in the same directory:

task createDevGwtXml(type: Copy) {
    from('src/main/java/com/saic/champion/upload/DevUpload.xml')
    into('src/main/java/com/saic/champion/upload/')
    rename ('src/main/java/com/saic/champion/upload/DevUpload.xml',
            'src/main/java/com/saic/champion/upload/DevUpload.gwt.xml')
}

DevUpload.xml exists at the given relative path. Running the task has no effect. Using --debug shows “Skipping task ‘createDevGwtXml’ as it is up-to-date” even though no copying happened. What does it take to copy a single file in the directory where it is currently located?

I’m using Gradle 1.0 milestone 6 on Ubuntu 10.10. Java 1.6.0_26


(Peter Niederwieser) #2

rename() takes file names, not file paths. Does this solve your problem?


(ian.durkan) #3

I believe that fixed the problem. Here’s the task I used:

task createDevGwtXmlA(type: Copy) {

from(‘src/main/java/com/saic/champion/upload/’)

into(‘src/main/java/com/saic/champion/upload/’)

include(‘DevUpload.xml’)

rename (‘DevUpload.xml’, ‘DevUpload.gwt.xml’)

filter (…filter closure defined elsewhere…) }


(shae eastman) #4

When I use this task format I get a copy but the renamed file comes out empty?


(Gavriel Fleischer) #5

this is my solution:

task copyTmpChangelog(type: Copy) {
  from "input"
  into '.'
  rename { String fileName ->
    fileName.replace("input", "output")
  }
}