Discussion:
Setting task inputs and outputs always gives UP-to-Date
k4rn4k
2012-03-27 12:12:51 UTC
Permalink
Hello,

Im setting this task outputs like shown in the user guide, but It's always
being resolved as "up to date as it has no source files".

task buildExplodedWar(type: Copy)<<{
//Configuring inputs/outputs
destDir = new File ("$project.buildDir/war")
project.configurations.runtime.each{srcFile ->
inputs.file srcFile
}
outputs.dir destDir
//Some copy behaviour
}

--
View this message in context: http://gradle.1045684.n5.nabble.com/Setting-task-inputs-and-outputs-always-gives-UP-to-Date-tp5597656p5597656.html
Sent from the gradle-user mailing list archive at Nabble.com.
Luke Daley
2012-03-27 12:19:58 UTC
Permalink
Post by k4rn4k
Hello,
Im setting this task outputs like shown in the user guide, but It's always
being resolved as "up to date as it has no source files".
task buildExplodedWar(type: Copy)<<{
//Configuring inputs/outputs
destDir = new File ("$project.buildDir/war")
project.configurations.runtime.each{srcFile ->
inputs.file srcFile
}
outputs.dir destDir
//Some copy behaviour
}
The problem is that you are setting them during task execution.

You need to rewrite as this:

task configureBuildExplodedWar << {
project.configurations.runtime.each { srcFile ->
buildExplodedWar.from srcFile
}
}

task buildExplodedWar(type: Copy, dependsOn: configureBuildExplodedWar) {
destination "$project.buildDir/war"
}

That should be all you need.

This is somewhat of a general pattern for delaying task configuration until execution, that we call “configuration tasks”.
--
Luke Daley
Principal Engineer, Gradleware
http://gradleware.com
Adam Murdoch
2012-03-27 23:20:58 UTC
Permalink
Post by Luke Daley
Post by k4rn4k
Hello,
Im setting this task outputs like shown in the user guide, but It's always
being resolved as "up to date as it has no source files".
task buildExplodedWar(type: Copy)<<{
//Configuring inputs/outputs
destDir = new File ("$project.buildDir/war")
project.configurations.runtime.each{srcFile ->
inputs.file srcFile
}
outputs.dir destDir
//Some copy behaviour
}
The problem is that you are setting them during task execution.
task configureBuildExplodedWar << {
project.configurations.runtime.each { srcFile ->
buildExplodedWar.from srcFile
}
}
task buildExplodedWar(type: Copy, dependsOn: configureBuildExplodedWar) {
destination "$project.buildDir/war"
}
Or even just

task buildExplodedWar(type: Copy) {
from configurations.runtime
destination "$project.buildDir/war"
}


--
Adam Murdoch
Gradle Co-founder
http://www.gradle.org
VP of Engineering, Gradleware Inc. - Gradle Training, Support, Consulting
http://www.gradleware.com
Luke Daley
2012-03-28 08:24:54 UTC
Permalink
Post by Adam Murdoch
Post by Luke Daley
Post by k4rn4k
Hello,
Im setting this task outputs like shown in the user guide, but It's always
being resolved as "up to date as it has no source files".
task buildExplodedWar(type: Copy)<<{
//Configuring inputs/outputs
destDir = new File ("$project.buildDir/war")
project.configurations.runtime.each{srcFile ->
inputs.file srcFile
}
outputs.dir destDir
//Some copy behaviour
}
The problem is that you are setting them during task execution.
task configureBuildExplodedWar << {
project.configurations.runtime.each { srcFile ->
buildExplodedWar.from srcFile
}
}
task buildExplodedWar(type: Copy, dependsOn: configureBuildExplodedWar) {
destination "$project.buildDir/war"
}
Or even just
task buildExplodedWar(type: Copy) {
from configurations.runtime
destination "$project.buildDir/war"
}
Ha, indeed. Forest for the trees.

Loading...