Having problems with Copy task not running thinking its UP-TO-DATE

I have a task like this:

task deployDataSource(type: Copy) {
   println "testenv is ${testEnv}"
  outputs.upToDateWhen {
     println "Is this even being called?"
    false
   }
  from project(':Library').files("build/install/${testEnv}/my-ds.xml")
  into "${jbossHome}/server/default/deploy/my-ds.xml"
}

Here’s what happens when I run the task

% gradle -deployDataSource
Note: the Gradle build daemon is an experimental feature.
As such, you may experience unexpected build failures. You may need to occasionally stop the daemon.
testenv is 'qa'
:webapp:MyApp:deployDataSource UP-TO-DATE

I added outputs.upToDateWhen closure in order to try to force the Copy task to run, because the task was thinking it was up-to-date when it wasn’t (IE, the target file does not exist), but it appears my closure is not being run because I don’t see my println statement logged in the log output.

I noticed a bug existed for the copy task related to this (http://issues.gradle.org/browse/GRADLE-872). However, that appears to be closed.

Am I doing something braindead stupid here?

Thanks.

Yes, as it turns out, I was doing something brain-dead stupid and just needed to take a break and come back again with a fresh pair of eyes.

The issu was that I was incorrectly setting a project property in my gradle.properties file:

testEnv=‘qa’

I didn’t need the quotes. This property was used to build up the path to the from setting in my copy task. Because the path was wrong, there was nothing to copy, which is why it was always getting marked as UP-TO-DATE. And, there was no need to call my upToDateWhen closure. When I removed the quotes, everything was working again.

It’s a common pitfall. IMHO it would be better if Gradle logged “skipped” here instead of “up-to-date”.

Ran into this as well. And “Skipped” is not good enough for us, we need our build to fail if the files that need copying are not copied because our input path is wrong.

I am also being bit in the buns by this. I have an environment specific config file that I need to add to a JAR file. I have been trying to get this to work:

task copyProps(type: Copy, dependsOn: cleanProps) {

doFirst {

if (!config.exists()) throw new IllegalArgumentException(“File " + config.toString() + " does not exist”)

logger.quiet(’>>> Creating job processor properties using meat from ’ + config.toString())

}

destinationDir = file(‘resources’)

if (config.exists()) {

def props = new Properties()

file(config).withInputStream { props.load(it); }

props.version = version

from(project(’:common’).fileTree(dir: ‘config/props/skel’)) {

include([’.properties’, '.xml’])

exclude(‘quartz.properties’)

filter(ReplaceTokens, tokens: props)

into(‘props’)

}

}

}

However, when the ‘config’ file above does not exist the copy task thinks it’s ‘UP-TO-DATE’ and I end up with no properties files in my JAR. This is pretty frustrating. Any work around?

Add the config file as an input…

task copyProps«…» {
  inputs.file config
}

task copyToRepo(type: Copy){

from “Welch.txt”

into “\\server1\repo”

}

  1. Why is it that it works for one server and for the other server it thinks that the task is UP-TO-DATE?

  2. It copies it, if I put “outputs.upToDateWhen { false }”. But then it hangs for like 25-30 min (Building 0% > :copyToRepo).

Any suggestions? What might be wrong with the other server???

Thank you!