user1147688 user1147688 - 28 days ago 18
Bash Question

Why doesn't gradle tasks show group or description when using exec?

My Gradle task stopped showing the

group
and
description
in
./gradlew tasks
, since I've added an
exec {}
in the root
build.gradle
.

What's going on, and how do I get it back?



task doSomething << {
group 'yourGroupName'
description 'Runs your bash script'
exec {
workingDir "$projectDir/../pathto/"
commandLine 'bash', '-c', './bashscript.sh'
}
}


Everything else works.

Answer

You cannot configure group and description in a doLast() closure

this code

task doSomething << {
    exec {
        workingDir "$projectDir/../pathto/"
        commandLine 'bash', '-c', './bashscript.sh'
    }
}

is the same than

task doSomething {
    doLast {
        exec {
            workingDir "$projectDir/../pathto/"
            commandLine 'bash', '-c', './bashscript.sh'
        }
    }
}

In the following group and description are not taking into account

task doSomething {
    doLast {
        group 'yourGroupName'
        description 'Runs your bash script'
        exec {
            workingDir "$projectDir/../pathto/"
            commandLine 'bash', '-c', './bashscript.sh'
        }
    }
}

But here it does :

task doSomething {
    group 'yourGroupName'
    description 'Runs your bash script'

    doLast {
        exec {
            workingDir "$projectDir/../pathto/"
            commandLine 'bash', '-c', './bashscript.sh'
        }
    }
}