I run into this now and then. I know that somehow this approach is not gradle friendly, but I’m not sure how to address it. I want to use the result of one task in the configuration of another. For example:
task firstTask(type:SomeStuff){
doLast {
println "Did stuff"
}
}
task secondTask(dependsOn:'firstTask'){
def result = firstTask.getResult()
doLast{
println "Use $result in this task"
}
}
public class SomeStuff extends DefaultTask{
private String stuff = "bad stuff"
@TaskAction
public void doStuff(){
println "Doing stuff"
stuff = "good stuff"
}
public String getResult(){
return stuff
}
}
The case I’m using this is with the asciidoctor plugin that needs its attributes set in the configuration. However, I have a task that needs to process and derive the attributes.
$ ./gradlew --daemon second
:first
Doing first stuff.
Did first.
:second
Doing second stuff
First result is first - stuff
In your question, you use asciidoctor plugin. The plugin defines @OutputDirectoryhere.
So you can use the output of the asciidoctor's task via Task's outputs property. For example copying asciidoctor's outputs into some directory…
task copyDoc(type: Copy, dependsOn: 'asciidoctor') {
from tasks['asciidoctor'].outputs.files
into file("${buildDir}/copyDoc")
}