Can Custom Method/Tasks declared in a Custom Plugin be called without using their fully qualified name


(Ipoo Doh) #1

Hi I have a custom plugin that declares a few task and also a few custom methods

//CustomPlugin .groovy
com.mycompany.gradle
  class CustomPlugin implements Plugin<Project> {
    void apply(Project project)
    {
           project.task('task1', type: task1){
                      }
          project.task('task2', type: task2){
                    }
            project.task('task3', type: task3){
                    }
      }
#CustomTasks .groovy
  com.mycompany.gradle
  class task1 extends DefaultTask
{
     def doSomething()
     {
            ...
      }
}
  class task2 extends DefaultTask
{
     def doSomething()
     {
            ...
      }
}
    class task3 extends DefaultTask
{
     def doSomething()
     {
            ...
      }
}

Also i have some custom methods

//CustomUtility.groovy
com.mycompany.gradle
  class CustomUtility
{
      def static Method1()
      {
           ...
      }
        def static Method2()
      {
           ...
      }
        def static Method3()
      {
           ...
      }
}
//Under the resources/META-INF.gradle.plugins/CustomPlugin.properties file i have
 implementation-class=com.mycomany.gradle.CustomPlugin

My gradle build file

//build.gradle
apply plugin: 'CustomPlugin'
  task Task1Type(type: com.mycompany.gradle.task1){
 doFirst{
   com.mycompany.gradle.CustomUtility.Method1()
  com.mycompany.gradle.CustomUtility.Method2()
  com.mycompany.gradle.CustomUtility.Method3()
 }
 }

I can call task1, task2, task3 directly without their fully qualified name though but I have to use their fully qualified name, if am going to instantiate a task of my custom task type or if I have to call my custom method.

Is there a way to avoid using their fully qualified name


(Ipoo Doh) #2

adding import statement works. possibly i made some mistakes before when it was erroring out when i included import statement

import com.mycompany.gradle.CustomUtility