title: How to execute a Gradle task once at the end of subproject tasks
body: <p>I am working with the following project structure</p>
  
  <pre><code>Project
  |-Subproject1
  |-Subproject2
  |build.gradle
  |settings.gradle
  </code></pre>
  
  <p>The submodules are included in the <code>settings.gradle</code> and configured in the <code>build.gradle</code> of the root project.</p>
  
  <p>I have 3 tasks to do</p>
  
  <ol>
  <li><code>build</code> (every subproject has this)</li>
  <li><code>deploy</code> (this is a packaging mechanism for every subproject needs to work on its own)</li>
  <li><code>finalizeDeployment</code> (this needs to be invoked only once)</li>
  </ol>
  
  <p>I want to be able to call </p>
  
  <p><code>$gradle deploy</code> &lt;- all subprojects get deployed and finalize gets called <strong>once</strong> at the end</p>
  
  <p><code>$gradle Subproject1:deploy</code> &lt;- Subproject1 gets deployed and finalize gets called</p>
  
  <p>build.gradle</p>
  
  <pre class="lang-groovy prettyprint-override"><code>configure(subprojects) {
  
      task build &lt;&lt;{
          println "Do Build "+ project.name
      }
  
      task deploy(dependsOn:build){
          println 'deploy '+project.name
  
          doLast{
              finalizeDeployment.execute()
          }
      }
  }
  
  task finalizeDeployment{
  
      dependsOn subprojects.deploy
  
      doLast{
          println 'Finalize Deployment'
      }
  }
  </code></pre>