{"id":18342547,"url":"https://github.com/bmuschko/gradle-cargo-plugin","last_synced_at":"2025-04-09T08:07:51.898Z","repository":{"id":43737178,"uuid":"1811194","full_name":"bmuschko/gradle-cargo-plugin","owner":"bmuschko","description":"Gradle plugin that provides deployment capabilities to local and remote containers via Cargo","archived":false,"fork":false,"pushed_at":"2022-02-20T22:43:14.000Z","size":1554,"stargazers_count":261,"open_issues_count":19,"forks_count":61,"subscribers_count":22,"default_branch":"master","last_synced_at":"2025-04-02T02:40:20.283Z","etag":null,"topics":["cargo","deployment","gradle-plugin","web"],"latest_commit_sha":null,"homepage":"","language":"Groovy","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bmuschko.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-05-27T18:35:55.000Z","updated_at":"2025-03-29T10:37:02.000Z","dependencies_parsed_at":"2022-09-08T05:00:27.410Z","dependency_job_id":null,"html_url":"https://github.com/bmuschko/gradle-cargo-plugin","commit_stats":null,"previous_names":[],"tags_count":42,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bmuschko%2Fgradle-cargo-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bmuschko%2Fgradle-cargo-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bmuschko%2Fgradle-cargo-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bmuschko%2Fgradle-cargo-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bmuschko","download_url":"https://codeload.github.com/bmuschko/gradle-cargo-plugin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247999859,"owners_count":21031046,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cargo","deployment","gradle-plugin","web"],"created_at":"2024-11-05T20:31:27.829Z","updated_at":"2025-04-09T08:07:51.872Z","avatar_url":"https://github.com/bmuschko.png","language":"Groovy","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Gradle Cargo plugin [![Build Status](https://github.com/bmuschko/gradle-cargo-plugin/workflows/Build%20and%20Release%20%5BLinux%5D/badge.svg)](https://github.com/bmuschko/gradle-cargo-plugin/actions?query=workflow%3A%22Build+and+Release+%5BLinux%5D%22)\n\n![Cargo Logo](https://codehaus-cargo.github.io/cargo/attachments/cargo-banner-left.png)\n\n\u003ctable border=1\u003e\n    \u003ctr\u003e\n        \u003ctd\u003e\n            Over the past couple of years this plugin has seen many releases. Thanks to everyone involved! \n            Unfortunately, I don't have much time to contribute anymore. In practice this means far less activity, \n            responsiveness on issues and new releases from my end.\n        \u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003e\n            I am \n            \u003ca href=\"https://discuss.gradle.org/t/looking-for-new-owners-for-gradle-plugins/9735\"\u003eactively looking for contributors\u003c/a\u003e \n            willing to take on maintenance and implementation of the project. If you are interested and would love to see this \n            plugin continue to thrive, shoot me a \u003ca href=\"mailto:benjamin.muschko@gmail.com\"\u003email\u003c/a\u003e.\n        \u003c/td\u003e\n    \u003c/tr\u003e\n\u003c/table\u003e\n\nThe plugin provides deployment capabilities for web applications to local and remote containers in any given\nGradle build by leveraging the [Cargo Ant tasks](https://codehaus-cargo.github.io/cargo/Ant+support.html). The plugin supports WAR and EAR\nartifacts.\n\nThe typical use case for this plugin is to support deployment during development. Keep in mind that Cargo uses hot deployment\nwhich over time fills up the PermGen memory of the JVM process running your container. Continuously deploying an artifact will\ninevitablity lead to a `java.lang.OutOfMemoryError`. Cargo does support container management capabilities (starting/stopping\nof remote containers) via the so-called [Cargo daemon](https://codehaus-cargo.github.io/cargo/Cargo+Daemon.html). However, in continuous deployment\nscenarios you often want to need perform more complex operations.\n\n## Usage\n\nTo use the plugin's functionality, you will need to add the its binary artifact to your build script's classpath and apply\nthe plugin.\n\n### Adding the plugin binary to the build\n\nThe plugin JAR needs to be defined in the classpath of your build script. It is available on the Gradle plugin portal. The following code snippet \nshows an example on how to retrieve it with the `buildscript` syntax:\n\n    buildscript {\n        repositories {\n            gradlePluginPortal()\n        }\n\n        dependencies {\n            classpath 'com.bmuschko:gradle-cargo-plugin:2.9.0'\n        }\n    }\n\n### Provided plugins\n\nThe JAR file comes with two plugins:\n\n\u003ctable\u003e\n    \u003ctr\u003e\n        \u003cth\u003ePlugin Identifier\u003c/th\u003e\n        \u003cth\u003eDepends On\u003c/th\u003e\n        \u003cth\u003eType\u003c/th\u003e\n        \u003cth\u003eDescription\u003c/th\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003ecom.bmuschko.cargo-base\u003c/td\u003e\n        \u003ctd\u003e-\u003c/td\u003e\n        \u003ctd\u003e\u003ca href=\"http://bmuschko.github.io/gradle-cargo-plugin/docs/groovydoc/com/bmuschko/gradle/cargo/CargoBasePlugin.html\"\u003eCargoBasePlugin\u003c/a\u003e\u003c/td\u003e\n        \u003ctd\u003eProvides Cargo custom task types, pre-configures classpath and deployables.\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003ecom.bmuschko.cargo\u003c/td\u003e\n        \u003ctd\u003ecom.bmuschko.cargo-base\u003c/td\u003e\n        \u003ctd\u003e\u003ca href=\"http://bmuschko.github.io/gradle-cargo-plugin/docs/groovydoc/com/bmuschko/gradle/cargo/CargoPlugin.html\"\u003eCargoPlugin\u003c/a\u003e\u003c/td\u003e\n        \u003ctd\u003eProvides a set of local and remote Cargo tasks and exposes extension for configuration.\u003c/td\u003e\n    \u003c/tr\u003e\n\u003c/table\u003e\n\nThe `com.bmuschko.cargo` plugin helps you get started quickly. If you only need to deal with a single container product, this is the\npreferrable option. Most plugin users will go with this option. To use the Cargo plugin, include the following code snippet\nin your build script:\n\n    apply plugin: 'com.bmuschko.cargo'\n\nIf you need full control over your deployment tasks, you will want to use the `com.bmuschko.cargo-base` plugin. The downside is that each task\nhas to be configured individually in your build script. To use the Cargo base plugin, include the following code snippet\nin your build script:\n\n    apply plugin: 'com.bmuschko.cargo-base'\n\n### Configuring the Cargo version\n\nThe `com.bmuschko.cargo-base` plugin already sets up the dependencies for Cargo. In order to do so, it chooses a default\nversion of the libraries. Alternatively, you can define a custom version of the Cargo libraries. To do so, please use\nthe `cargo` configuration name in your `dependencies` closure, and keep the below in mind:\n* Remote deployment functionality will only work with a Cargo version \u003e= 1.1.0 due to a bug in the library (see [CARGO-962](https://codehaus-cargo.atlassian.net/browse/CARGO-962) for more information).\n* Setting configuration properties will only work with a Cargo version \u003e= 1.9.10 due to missing feature in the library (see [CARGO-1578](https://codehaus-cargo.atlassian.net/browse/CARGO-1578) for more information).\nThe following example demonstrates how to use the version 1.9.10 of the Cargo libraries:\n\n```\ndependencies {\n    def cargoVersion = '1.9.10'\n    cargo \"org.codehaus.cargo:cargo-core-uberjar:$cargoVersion\",\n          \"org.codehaus.cargo:cargo-licensed-dtds:$cargoVersion\",\n          \"org.codehaus.cargo:cargo-ant:$cargoVersion\"\n}\n```\n\n## Tasks\n\nThe `cargo` plugin pre-defines the following tasks out-of-the-box:\n\n\u003ctable\u003e\n    \u003ctr\u003e\n        \u003cth\u003eTask Name\u003c/th\u003e\n        \u003cth\u003eDepends On\u003c/th\u003e\n        \u003cth\u003eType\u003c/th\u003e\n        \u003cth\u003eDescription\u003c/th\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003ecargoDeployRemote\u003c/td\u003e\n        \u003ctd\u003e-\u003c/td\u003e\n        \u003ctd\u003e\u003ca href=\"http://bmuschko.github.io/gradle-cargo-plugin/docs/groovydoc/com/bmuschko/gradle/cargo/tasks/remote/CargoDeployRemote.html\"\u003eCargoDeployRemote\u003c/a\u003e\u003c/td\u003e\n        \u003ctd\u003eDeploys a deployable to remote container.\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003ecargoUndeployRemote\u003c/td\u003e\n        \u003ctd\u003e-\u003c/td\u003e\n        \u003ctd\u003e\u003ca href=\"http://bmuschko.github.io/gradle-cargo-plugin/docs/groovydoc/com/bmuschko/gradle/cargo/tasks/remote/CargoUndeployRemote.html\"\u003eCargoUndeployRemote\u003c/a\u003e\u003c/td\u003e\n        \u003ctd\u003eUndeploys a deployable from remote container.\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003ecargoRedeployRemote\u003c/td\u003e\n        \u003ctd\u003e-\u003c/td\u003e\n        \u003ctd\u003e\u003ca href=\"http://bmuschko.github.io/gradle-cargo-plugin/docs/groovydoc/com/bmuschko/gradle/cargo/tasks/remote/CargoRedeployRemote.html\"\u003eCargoRedeployRemote\u003c/a\u003e\u003c/td\u003e\n        \u003ctd\u003eRedeploys a deployable to remote container.\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003ecargoRunLocal\u003c/td\u003e\n        \u003ctd\u003e-\u003c/td\u003e\n        \u003ctd\u003e\u003ca href=\"http://bmuschko.github.io/gradle-cargo-plugin/docs/groovydoc/com/bmuschko/gradle/cargo/tasks/local/CargoRunLocal.html\"\u003eCargoRunLocal\u003c/a\u003e\u003c/td\u003e\n        \u003ctd\u003eStarts the local container, deploys a deployable and waits for the user to press CTRL + C to stop.\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003ecargoStartLocal\u003c/td\u003e\n        \u003ctd\u003e-\u003c/td\u003e\n        \u003ctd\u003e\u003ca href=\"http://bmuschko.github.io/gradle-cargo-plugin/docs/groovydoc/com/bmuschko/gradle/cargo/tasks/local/CargoStartLocal.html\"\u003eCargoStartLocal\u003c/a\u003e\u003c/td\u003e\n        \u003ctd\u003eStarts the local container, deploys a deployable and then do other tasks (for example, execute tests).\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003ecargoRedeployLocal\u003c/td\u003e\n        \u003ctd\u003e-\u003c/td\u003e\n        \u003ctd\u003e\u003ca href=\"http://bmuschko.github.io/gradle-cargo-plugin/docs/groovydoc/com/bmuschko/gradle/cargo/tasks/local/CargoRedeployLocal.html\"\u003eCargoRedeployLocal\u003c/a\u003e\u003c/td\u003e\n        \u003ctd\u003eRedeploys a deployable on local container.\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003ecargoStopLocal\u003c/td\u003e\n        \u003ctd\u003e-\u003c/td\u003e\n        \u003ctd\u003e\u003ca href=\"http://bmuschko.github.io/gradle-cargo-plugin/docs/groovydoc/com/bmuschko/gradle/cargo/tasks/local/CargoStopLocal.html\"\u003eCargoStopLocal\u003c/a\u003e\u003c/td\u003e\n        \u003ctd\u003eStops local container.\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003ecargoConfigureLocal\u003c/td\u003e\n        \u003ctd\u003e-\u003c/td\u003e\n        \u003ctd\u003e\u003ca href=\"http://bmuschko.github.io/gradle-cargo-plugin/docs/groovydoc/com/bmuschko/gradle/cargo/tasks/local/CargoConfigureLocal.html\"\u003eCargoConfigureLocal\u003c/a\u003e\u003c/td\u003e\n        \u003ctd\u003eConfigures the local container.\u003c/td\u003e\n    \u003c/tr\u003e\n\u003c/table\u003e\n\n## Project layout\n\nThe Cargo plugin uses the same layout as the War plugin.\n\n## Extension properties\n\nThe Cargo plugin defines the following convention properties in the `cargo` closure:\n\n* `containerId`: The container ID you are targeting. Please see the [list of supported containers](https://codehaus-cargo.github.io/cargo/Home.html) on the Cargo website.\n* `port`: The TCP port the container responds on (defaults to 8080).\n\nWithin `cargo` you can define optional properties for the 1..n deployment artifacts in a closure named `deployable`. Each\ndeployment artifact would be specified in its own closure:\n\n* `file`: Any type that can be passed to [Project.files(Object...)](https://docs.gradle.org/current/javadoc/org/gradle/api/Project.html#files-java.lang.Object...-) and resolves to a single file or a directory including arbitrary artifacts, exploded WAR directories and dependency configurations to be deployed to container (defaults to project/module artifact - WAR or EAR file).\n* `context`: The URL context the container is handling your web application on (defaults to WAR/EAR name).\n\nKeep in mind that you do not have to define the `deployable` closure if you just want to deploy the artifact defined by your\nGradle project/module.\n\nWithin `cargo` you can define properties for remote containers in a closure named `remote`:\n\n* `protocol`: The protocol of the remote container (defaults to `http`).\n* `hostname`: The hostname of the remote container.\n* `username`: The username credential for the remote container (optional).\n* `password`: The password credential for the remote container (optional).\n\nWithin `cargo` you can define properties for local containers in a closure named `local`:\n\n* `jvmArgs`: The JVM arguments for a local container.\n* `outputFile`: The log file of your local container (defaults to writing to the console).\n* `logFile`: The Cargo log file of your local container (defaults to writing to the console).\n* `logLevel`: The log level to run the container with (optional). The valid levels are `low`, `medium` and `high`.\n* `homeDir`: The home directory of your local container installation.\n* `configHomeDir`: The home directory of your local container's configuration.\n* `configFile`: The [configuration files](https://codehaus-cargo.github.io/cargo/Configuration+files+option.html) you want to add to your\ncontainer's configuration. The `configFile` is a closure itself and requires you to provide the attributes `files` and `toDir`.\nA [`FileCollection`](http://www.gradle.org/docs/current/javadoc/org/gradle/api/file/FileCollection.html) should be used as `files` attribute and `toDir` should be a `String`.\nMultiple configuration file destinations can be defined by creating more than one `configFile` closure.\n* `rmiPort`: The port to use when communicating with this server, for example to start and stop it.\n* `startStopTimeout`: The timeout (in ms) in which to determine if the container is successfully started or stopped (defaults to 120000ms).\n* `extraClasspath`: A [`FileCollection`](http://www.gradle.org/docs/current/javadoc/org/gradle/api/file/FileCollection.html)\nthat provides extra elements to the local [container classpath](http://cargo.codehaus.org/Container+Classpath) (optional).\n* `sharedClasspath`: A [`FileCollection`](http://www.gradle.org/docs/current/javadoc/org/gradle/api/file/FileCollection.html)\nthat provides extra elements to the [application classpath](https://codehaus-cargo.github.io/cargo/Application+Classpath.html), and not to the\nlocal container (optional).\n\n### Container properties\n\nWithin `local` and `remote` you can define container-specific properties. These properties can be looked up on\nthe Cargo homepage. The following example shows how to set the AJP port for a local Tomcat container:\n\n    cargo {\n        local {\n            containerProperties {\n                property 'cargo.tomcat.ajp.port', 9099\n            }\n        }\n    }\n\n### System properties\n\nLocal containers can use system properties passed to it. The following example shows how to set a single system property named `myproperty`:\n\n    cargo {\n        local {\n            systemProperties {\n                property 'myproperty', 'myvalue'\n            }\n        }\n    }\n\n### Automatically bootstrapping a local container\n\nIf you decide to use the [ZIP installer](https://codehaus-cargo.github.io/cargo/Installer.html) Cargo will automatically download your container. You can\ndefine its properties in the closure `installer`. The installer only applies to \"local\" Cargo tasks.\n\n* `installUrl`: The URL to download the container distribution from.\n* `downloadDir`: Target directory to download the container distribution to.\n* `extractDir`: Directory to extract the downloaded container distribution to.\n\nPlease refer to the individual configuration properties on the Cargo homepage. All of these properties can be overridden\nby project properties. The name of the project properties is the same as in the Cargo manual.\n\nIf you wish to benefit from Gradle dependency cache when resolving container distributions you can use a configuration instead of a url when configuring the installer:\n\n    configurations {\n        tomcat\n    }\n    \n    dependencies {\n        tomcat \"org.apache.tomcat:tomcat:9.0.14@zip\"\n    }\n    \n    cargo {\n        local {\n            installer {\n                installConfiguration = configurations.tomcat\n            }\n        }\n    }\n\n### Example\n\n    cargo {\n        containerId = 'tomcat6x'\n        port = 9090\n\n        deployable {\n            context = 'myawesomewebapp'\n        }\n\n        remote {\n            hostname = 'cloud.internal.it'\n            username = 'superuser'\n            password = 'secretpwd'\n        }\n\n        local {\n            homeDir = file('/home/user/dev/tools/apache-tomcat-6.0.32')\n            outputFile = file('build/output.log')\n            startStopTimeout = 60000\n\n            containerProperties {\n                property 'cargo.tomcat.ajp.port', 9099\n            }\n        }\n    }\n\n## FAQ\n\n**I want to automatically assemble my project's artifact when executing a Cargo deployment task.**\n\nThe task `cargoRunLocal` does not automatically depend on the `assemble` task. The reason behind that is that you might\nnot want to deploy your project's artifact or your project does not generate a WAR or EAR file. Instead you might want\nto deploy one or more external artifacts. If your workflow looks like \"compile the code\", \"generate the artifact\" and \"deploy\"\nthen you make a Cargo deployment task depends on the `assemble` task. Here's one example:\n\n    cargoRunLocal.dependsOn assemble\n\n**I am working on a multi-project build. Can I apply the same Cargo configuration to all of my web projects?**\n\nGradle allows for filtering subprojects by certain criteria. To inject the relevant configuration from the root project\nof your build, you will need to identify all subprojects that apply the War plugin (of course the same concept works\nfor Ear projects). Use the `configure` method to apply the Cargo plugin and your configuration as shown in the following\ncode snippet:\n\n    def webProjects() {\n        subprojects.findAll { subproject -\u003e subproject.plugins.hasPlugin('war') }\n    }\n\n    gradle.projectsEvaluated {\n        configure(webProjects()) {\n            apply plugin: 'com.bmuschko.cargo'\n\n            cargo {\n                containerId = 'tomcat7x'\n\n                remote {\n                    hostname = 'localhost'\n                    username = 'manager'\n                    password = 'manager'\n                }\n            }\n        }\n    }\n\n**I would like to deploy multiple artifacts to my container. How do I do that?**\n\nYou would specify each artifact in a separate `deployable` closure. Each of the closures should assign a unique URL context.\nThe following example demonstrates how a Cargo setup with three different artifacts deployed to a local Tomcat:\n\n    cargo {\n        containerId = 'tomcat6x'\n        port = 9090\n\n        deployable {\n            file = file('/home/foo/bar/web-services.war')\n            context = 'web-services'\n        }\n\n        deployable {\n            file = file('/home/foo/bar/web-app.war')\n            context = 'web-app'\n        }\n\n        deployable {\n            file = file('/home/foo/bar/enterprise-app.ear')\n            context = 'enterprise-app'\n        }\n\n        local {\n            homeDir = file('/home/user/dev/tools/apache-tomcat-6.0.32')\n        }\n    }\n\n**Is there a way to let Cargo automatically install the container I'd like to use?**\n\nCargo allows for defining a container that gets automatically downloaded and installed on your local disk. All you need to\ndo is to specify the `installer` closure. The following code snippet downloads, installs and uses Tomcat 7:\n\n    cargo {\n        containerId = 'tomcat7x'\n\n        local {\n            installer {\n                installUrl = 'http://apache.osuosl.org/tomcat/tomcat-7/v7.0.27/bin/apache-tomcat-7.0.27.zip'\n                downloadDir = file(\"$buildDir/download\")\n                extractDir = file(\"$buildDir/extract\")\n            }\n        }\n    }\n\n**I'd like to add a configuration file to my local container. How do I do that?**\n\nFor local containers a closure named `configFile` can be used that defines the source files and directory you would like\nto use the file from at runtime. If you need to copy files into more than one destinations just create multiple `configFile` closures.\n\n    cargo {\n        containerId = 'jboss5x'\n\n        local {\n            configFile {\n                files = project.files('src/main/jboss5/login-config.xml')\n                toDir = 'conf'\n            }\n\n            configFile {\n                files = project.files('src/main/jboss5/login-config.xml', 'src/main/jboss5/sample-users.properties')\n                toDir = 'conf/props'\n            }\n        }\n    }\n\nTo add binary file(s) you should use `file` closure(s) instead:\n\n    cargo {\n        containerId = 'glassfish3x'\n\n        local {\n            file {\n                file = file('../config/db/mysql-connector-java-5.1.23-bin.jar')\n                toDir = 'lib'\n            }\n        }\n    }\n\n**I want to set up and configure my own Cargo task for more than one container. Can this be done?**\n\nAbsolutely. The Cargo base plugin provides all tasks needed to set up deployment tasks. All you need to do is to create one\nor more tasks and configure the mandatory properties. The following example shows how to set up local container tasks\nfor Tomcat and Jetty:\n\n    apply plugin: 'com.bmuschko.cargo-base'\n\n    task myTomcatRun(type: com.bmuschko.gradle.cargo.tasks.local.CargoRunLocal) {\n        containerId = 'tomcat7x'\n        homeDir = file('/home/user/dev/tools/apache-tomcat-7.0.42')\n    }\n\n    task myJettyRun(type: com.bmuschko.gradle.cargo.tasks.local.CargoRunLocal) {\n        containerId = 'jetty9x'\n        homeDir = file('/home/user/dev/tools/jetty-distribution-9.0.4.v20130625')\n    }\n\n**I'd like to create deployment tasks for a rolling deployment to multiple remote containers. How do I do this?**\n\nGradle allows for dynamically creating tasks based on your build script logic. The following example shows how to create\nthree Tomcat deployment tasks and how to configure them with the help of a simple data structure. At the end of the script we\nalso add another task that triggers the deployment to all remote containers.\n\n    class RemoteContainer {\n        String name\n        String hostname\n        Integer port\n        String username\n        String password\n    }\n\n    def remoteContainers = [new RemoteContainer(name: 'tomcat1', hostname: 'remote-tomcat1',\n                                                port: 9090, username: 'admin', password: 's3cr3t'),\n                            new RemoteContainer(name: 'tomcat2', hostname: 'remote-tomcat2',\n                                                port: 8050, username: 'deployer', password: 'qwerty'),\n                            new RemoteContainer(name: 'tomcat3', hostname: 'remote-tomcat3',\n                                                port: 8888, username: 'su', password: 'powerful')]\n\n    apply plugin: 'com.bmuschko.cargo-base'\n\n    remoteContainers.each { config -\u003e\n        task \"deployRemote${config.name.capitalize()}\"(type: com.bmuschko.gradle.cargo.tasks.remote.CargoDeployRemote) {\n            description = \"Deploys WAR to remote Tomcat '${config.name}'.\"\n            containerId = 'tomcat7x'\n            hostname = config.hostname\n            port = config.port\n            username = config.username\n            password = config.password\n        }\n    }\n\n    task deployToAllRemoteTomcats {\n        dependsOn remoteContainers.collect { \"deployRemote${it.name.capitalize()}\" }\n        description = 'Deploys to all remote Tomcat containers.'\n        group = 'deployment'\n    }\n\n**Before a remote deployment I would like to restart my container. Can this be done?**\n\nYes, this is possible with the help of the [Cargo daemon](https://codehaus-cargo.github.io/cargo/Cargo+Daemon.html) functionality. Please\nrefer to the Cargo online documentation for setting up the Cargo daemon JVM process and configuring a container. With\nthis plugin, you can use custom tasks to start and stop a container. The following example stops, starts and then redeploys\nan artifact.\n\n    apply plugin: 'com.bmuschko.cargo'\n\n    cargo {\n        ...\n    }\n\n    ext.tomcat7HandleId = 'tomcat7'\n\n    task cargoDaemonStop(type: com.bmuschko.gradle.cargo.tasks.daemon.CargoDaemonStop) {\n        handleId = tomcat7HandleId\n    }\n\n    task cargoDaemonStart(type: com.bmuschko.gradle.cargo.tasks.daemon.CargoDaemonStart) {\n        handleId = tomcat7HandleId\n    }\n\n    cargoDaemonStart.mustRunAfter cargoDaemonStop\n    cargoRedeployRemote.dependsOn cargoDaemonStop, cargoDaemonStart\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbmuschko%2Fgradle-cargo-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbmuschko%2Fgradle-cargo-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbmuschko%2Fgradle-cargo-plugin/lists"}