eleven eleven - 3 months ago 16
Groovy Question

Importing only one task from gradle file

Am I right that there is no way to import only one

task
from script file into a project? I have utility
task
which should be in a list of tasks.

task utiliyTask{
description 'Utility task which you could to run when you need it'
funA()
funB()
}

def funA(){
//...
}

def funB(){
//...
}


Putting
apply from
into a project's
build.gradle
file executes this task automatically which is wrong. The only solution which I found is creating plugin, but it seems like overkill to create a plugin for 100 lines of utility script

Answer

The solution is to simply add task execution code into doLast

task utiliyTask{
  description 'Utility task which you could to run when you need it'
  doLast {
    funA()
    funB()
  }  
}
Comments