How can I use the result of task1 in the configuration of task2?

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()
    println "Use $result in this task"

public class SomeStuff extends DefaultTask{
  private String stuff = "bad stuff"
  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.

What is a good approach for this?

You can use the result of dependent task.

This is the script you wrote(customized a little).

class SomeStuff extends DefaultTask {
    String stuff
    void doStuff() {
        println "Doing ${name} stuff."
        stuff = "${name} - stuff"
task first(type: SomeStuff) {
    doLast {
        println 'Did first.'
task second(type: SomeStuff, dependsOn: 'first') {
    def fs = tasks['first']
    doLast {
        println "First result is ${fs.stuff}."

If you run task second, it shows like this.

$ ./gradlew --daemon second
Doing first stuff.
Did first.
Doing second stuff
First result is first - stuff

In your question, you use asciidoctor plugin. The plugin defines @OutputDirectory here.
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")

Ahhhhhh! That’s awesome, that gives me a whole new set of options to
reference the task that way. Thank you, Shinya, I really appreciate it!