Gradle : What are task alias short forms

What is a Gradle Task alias

Suppose we have a gradle file as below

build.gradle

task copyAllFiles(){
    doLast{
        println "copyAllFiles"
    }
}

task copySomeFiles(){
    doLast{
        println "copyAllFiles"
    }
}

task copyParticularFiles(){
    doLast{
        println "copyAllFiles"
    }
}

Now to run the above tasks we have to run the following commands

gradle -q copyAllFiles
gradle -q copySomeFiles
gradle -q copyParticularFiles

However we can also run the gradle tasks by unique names that diffrenetiates the tasks for example

gradle -q cAF // short form for copyAllFiles
gradle -q cSF // short form for copySomeFiles
gradle -q cPF // short form for copyParticularFiles

but if we run a task with a short name that does not uniquely define a task then it will trow an exception. for example

gradle -q copy

will throw the execption

FAILURE: Build failed with an exception.

* What went wrong:
Task 'copy' is ambiguous in root project 'Gradle Tutorial'. Candidates are: 'copyAllFiles', 'copyParticularFiles', 'copySomeFiles'.

Also note, that the characters used for short form are case sensitive, so cAF will run the task copyAllFiles but caf will not.

No comments:

Powered by Blogger.