The Tomcat and the Cargo plugins are two distinct plugins and do not work with one another in the way your tried to solve your problem. The Tomcat plugin only provides an in-memory, embedded container for Tomcat (meaning you don't have to have a local installation) whereas Cargo requires you to either point to a local container installation or a remote URL. For your purposes, I'd exclusively go with the Cargo plugin.
All the code you define in your tasks is executed during the configuration phase. Using the DSL of the Cargo plugin in multiple tasks will override the previous declaration. For a better understanding on execution vs. configuration phase, I'd recommend checking the Gradle online user guide. Keep in mind that Cargo in general does not provide management functionality for remote containers (starting/stopping). This was also mentioned in the README file of the plugin. If you want to do something like that, you'd have to write tasks that run remote SSH commands.
Apart from not being able to start/stop containers with the plugin, your actual problem can be solved in multiple ways. Either you use the Cargo plugin DSL and assign the remote hostname, port, username, password dynamically or you create multiple tasks. It seems like you still want to create multiple tasks for each environment. For that apply the cargo-base
plugin and create two tasks of type CargoDeployRemote
, one for your dev and one for your QA environment. In that scenario you are not using the DSL exposed by the plugin. Of course you'd create another task for your local Tomcat installation as well with the appropriate task type.
apply plugin: 'cargo-base'
import com.bmuschko.gradle.cargo.convention.Deployable
import com.bmuschko.gradle.cargo.tasks.remote.CargoDeployRemote
task deployToQA(type: CargoDeployRemote) {
containerId = 'tomcat7x'
hostname = server_address_qa
port = TomcatPortQA as Integer
username = username_qa
password = password_qa
deployables = [new Deployable(file: file(warLocation), context: 'web-application')]
}