Depending on tasks created in afterEvalute by plugin

plugins

(Kunal Dabir) #1

Imagine a plugin exposing an extension as following…

myExt {
  root name:'a', file:file('a')
  root name:'b', file:file('b')
}

such that for each root, the plugin adds a task copyRootX. Plugin has to create these tasks in afterEvaluate block so that it can use the configured extension object.

The problem is, although the tasks are correctly added and work fine, they can not be depended upon or referred to in the build script just like the normal tasks. Hence user has to be aware of referring to task name in afterEvaluate or any other ‘lazy’ way.

for example, the following won’t work:

task publishData (type:Copy) {
  from copyRootA.destinationDir
  into 'someDir'
}

The build script fails as the copyRootA task has not been added to the project yet. However something like this would work.

task publishData (type:Copy) {
    project.afterEvaluate {
       from copyRootA.destinationDir
       into 'someDir'
   }
}

How to author a plugin which won’t have this problem?

PS: code examples above are pseudocode representation of my actual problem


(Kunal Dabir) #2

<Bump/> any suggestions ?


(Mark Vieira) #3

This is a very common problem. Although not a public API, using convention mapping is really the best solution.