Vyacheslav
Vyacheslav

Reputation: 1256

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!

Upvotes: 5

Views: 2455

Answers (1)

Vyacheslav
Vyacheslav

Reputation: 1256

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')
         }
     }
  }

Upvotes: 5

Related Questions