title: Gradle during its execution phase, adding and executing tasks dynamically
body: <p>I have the requirement to create and execute tasks during Gradle's execution phase.</p>
  
  <p>Currently, during my build task I determine and create multiple tasks which I add to the taskContainer, using: </p>
  
  <p><code>tasks.add([name: "$taskName", type: "$taskType"], {...})</code></p>
  
  <p>and then after all the tasks are added I execute them sequentially, using:</p>
  
  <p><code>tasks["$taskName"].execute()</code></p>
  
  <p>On the first execution I get the following error:</p>
  
  <p>> The task artifact state cache (.../.gradle/1.5/taskArtifacts) has not been locked.</p>
  
  <p><strong>What am I doing wrong, and is there a better way to dynamically add tasks during execution?</strong></p>