Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Gradle plugin configuration properties at the evaluation phase

I'm writing my own gradle plugin and want to define an additional Copy task. What I do is:

myPlugin {
    scriptsDir = "otherDir"
}

class MyPluginExtension {
    String scriptsDir = "scripts";
}    

class MyPlugin implements Plugin<Project> {

   @Override
   void apply(Project project) {
      project.extensions.create("myPlugin", MyPluginExtension)

      project.task("myDistCopy", type: Copy) {
         .....
         from(project.myPlugin.scriptDir) {
            into('bin')
         }
      }
   }
}

Unfortunately the files are still copied from the "scripts" folder instead of "otherDir". It seems that the extension properties are not set at the evaluation phase. Do you have any ideas how can I refer to the myPlugin settings in the Copy task?

Thanks!

like image 452
Vyacheslav Avatar asked Oct 01 '22 04:10

Vyacheslav


1 Answers

Actually the solution that worked for me turned out to be pretty simple:

project.task("myDistCopy", type: Copy) {
     .....
     project.afterEvaluate {
         from(project.myPlugin.scriptDir) {
            into('bin')
         }
     }
  }
like image 128
Vyacheslav Avatar answered Oct 06 '22 20:10

Vyacheslav