Sorry for what must sound like a trivial question, but this still escapes me.
I want to copy the result of java compile (the class files) to another directory (copy, not move).
However, if I create a Copy task, all I can do in specifying dependencies is say
compileJava.dependsOn myCopyTask
which is not what i want, I want something like:
myCopyTask.dependsOn compileJava
or more to the point (but not gradle syntax)
compileJava.doAfter myCopyTask
However, there is no ‘doAfter’.
So, how do I do it?
I have tried this kind of syntax, but it doesn’t seem to run.
compileJava {
doLast {
copy {
from sourceSets.main.runtimeClasspath
into "$buildDir/classes-copy"
include '*.class'
}
}
}
I realize I could probably create a copy task on which the ‘processResources’ task depends, which would achieve the same thing ( I think ), except, I want to make sure that ‘myCopyTask’ runs if and only if the ‘compileJava’ task runs…
(not depending on if the processResources task runs).
Just depending the copy task on ‘compileJava’ works as you intend for the “up-to-date” part. I’m not sure about the “skipped”. At least it seems to work on a quick test.
I think the correct approach is:
Have ‘compileJava’ unaltered. * Depend the copy task on ‘compileJava’. * Depend any task using the copied files on the copy task.
Task B cannot be up-to-date, when compileJava is run (and not up-to-date). Since compileJava is outdated, the copy task is outdated, task B is outdated.
If you don’t run task B, then why should you have to run the copy task?