title: Using Gradle Cargo plugin to deploy to multiple environments
body: <p>I am trying to have multiple Gradle tasks in my <code>build.gradle</code> file to deploy a war to different environments. I want to be able to have a <code>deployToLocal</code> task along with <code>deployToQA</code> and <code>deployToDev</code>, after a war file has been generated. </p>
  
  <p>Of course, this means that I want to stop the Tomcat service, delete existing war files and expanded wars in the Tomcat webapps directory, copy the war, and restart Tomcat again to deploy the service.</p>
  
  <p>My question is twofold:</p>
  
  <ol>
  <li>I have specified the location of the war that I will be copying
  along with all the hostname, port and username/ password
  information. My question is: how do I specify which location in the
  remote environments (directory structure) the war should be copied
  into?</li>
  <li>For the end I am trying to achieve, is this the correct way to move forward?</li>
  </ol>
  
  <p>My code so far:</p>
  
  <pre><code>task deleteDirLocalhost(type: Delete){
      //delete fileTree(dir: local_Tomcat_webapps_dir)
      delete fileTree(dir: 'C:\\Tomcat7.0\\webapps')
  }
  
  task deployToLocal{
      dependsOn war, tomcatStop, deleteDirLocalhost
      println "Starting Cargo"
      println "Using war from: $warLocation"              // warLocation is a variable defined in gradle.properties file
  
      cargo {
          containerId = 'tomcat7x'
          port = TomcatPortLocalhost as Integer
          local {
              homeDir = file(local_Tomcat_webapps_dir)    // local_Tomcat_webapps_dir is a variable defined in gradle.properties file
          }
  
          deployable {
              file = file(warLocation)            // This is where I specify where the war file is to be copied from. In the 'local' section, I have specified 'homeDir' as the location where I want this file to be copied to. Is that correct usage?
              context = 'web-application'
          }
      }
      tomcatRunWar
  }
  
  task deployToQA{
      dependsOn war, tomcatStop, deleteDirQA
      println "Starting Cargo"
      println "Using war from: $warLocation"
  
      cargo {
          containerId = 'tomcat7x'
          port = TomcatPortQA as Integer
          remote {
              hostname = server_address_qa        // all these are variables defined in the gradle.properties file
              username = username_qa
              password = password_qa
          }
  
          deployable {
              file = file(warLocation)           // This is where I specify the location of the war file. How do I specify in the 'remote' section in which directory in the server this file should be copied to?
              context = 'web-application'
          }
      }
      tomcatRunWar
  }
  
  task deployToDev{
      dependsOn war, tomcatStop, deleteDirDev
      println "Starting Cargo"
      println "Using war from: $warLocation"
  
      cargo {
          containerId = 'tomcat7x'
          port = TomcatPortDev as Integer
          remote {
              hostname = RT3_webapp_address_dev
              username = username_dev
              password = password_dev
          }
  
          deployable {
              file = file(warLocation)
              context = 'web-application'
          }
      }
      tomcatRunWar
  }
  </code></pre>
  
  <p>I want to call task <code>gradle deployToLocal</code> and expect the behavior that local Tomcat instance is stopped, the war is copied to my Tomcat\webapps folder (with any previously existing files or folders in the same folder having been deleted), and then the Tomcat service is started again and the war is deployed.</p>
  
  <p>This doesn't work, and obviously I am missing something. I also scoured the web for a solid fully-worked-out example of an implementation of the gradle cargo/ tomcat plugin without much luck. Could someone please point me in the right direction? </p>
  
  <p>Thank you in advance for any help!</p>