Jordi
Jordi

Reputation: 23187

Connect war task to cargo deploy task

I've create a gradle script in order to deploy a deployable on a container using cargo plugin:

class RemoteContainer {
    String name
    String container
    String hostname
    Integer port
    String username
    String password
    String purpose
}

def remoteContainers = [new RemoteContainer(
        name: 'wildfly10',
        container: 'wildfly10x',
        hostname: 'localhost',
        port: 9990,
        username: 'user',
        password: 'passwd',
        purpose: 'development'
    )
]

remoteContainers.each { config ->
    task "deployDev${config.name.capitalize()}"(type: com.bmuschko.gradle.cargo.tasks.remote.CargoDeployRemote) {
        description = "Deploys WAR to remote Web Application Server: '${config.name}'."
        containerId = config.container
        hostname = config.hostname
        port = config.port
        username = config.username
        password = config.password
        dependsOn war
    }

    task "undeployDev${config.name.capitalize()}"(type: com.bmuschko.gradle.cargo.tasks.remote.CargoUndeployRemote) {
        description = "Deploys WAR to remote Web Application Server: '${config.name}'."
        containerId = config.container
        hostname = config.hostname
        port = config.port
        username = config.username
        password = config.password
        dependsOn = war
    }
}

Nevertheless, I've created several tasks in order to create custom war files according to its scope:

task createQAWar(type: War, dependsOn: classes) {
    archiveName "webapi-demo-${versioning.info.display}.war"
    destinationDir = file("$buildDir/dist")
    webInf {
       ...
    }
}

task createDevelopmentWar(type: War, dependsOn: classes) {
    archiveName "webapi-dev-${versioning.info.display}.war"
    destinationDir = file("$buildDir/dist")
    webInf {
       ...
    }
}

task createTestingWar(type: War, dependsOn: classes) {
    archiveName "webapi-test-${versioning.info.display}.war"
    destinationDir = file("$buildDir/dist")
    webInf {
       ...
    }
}

task createProductionWar(type: War, dependsOn: classes) {
    archiveName "webapi-prod-${versioning.info.display}.war"
    destinationDir = file("$buildDir/dist")
    webInf {
       ...
    }
}

I'd like to link that deployDev tasks pick the war artifact generated on createDevelopmentWar.

I've tried to set dependsOn property to createDevelopmentWar:

remoteContainers.each { config ->
    task "deployDev${config.name.capitalize()}"(type: com.bmuschko.gradle.cargo.tasks.remote.CargoDeployRemote) {
        description = "Deploys WAR to remote Web Application Server: '${config.name}'."
        containerId = config.container
        hostname = config.hostname
        port = config.port
        username = config.username
        password = config.password
        dependsOn = createDevelopmentWar  <<<<<<<<<<<<<<<<<
    }
}

Nevertheless, gradle it's getting me this message:

  • What went wrong: A problem occurred evaluating root project 'webapi'. Cannot cast object 'task ':createDevelopmentWar'' with class 'org.gradle.api.tasks.bundling.War_Decorated' to class 'java.lang.Iterable '

I've also tried setting dependsOn to war task, nevertheless the message is the same.

EDIT

Once, I've changed the syntax for dependsOn = [createDevelopmentWar], I'm facing up with another trouble:

It's getting me this message:

Execution failed for task ':deployDevWildfly10'. Deployable D:\projects\living\platform\webapi\build\libs\webapi-dev-89c157a-dirty.war does not exist

It's trying to get the artifact from build\libs\. Nevertheless, the war artifact has been created in destinationDir = file("$buildDir/dist"):

task createDevelopmentWar(type: War, dependsOn: classes) {
        archiveName "webapi-dev-${versioning.info.display}.war"
        destinationDir = file("$buildDir/dist")
        webInf {
           ...
        }
    }

How could I set cargo picks the artifact up from previously war type task(createDevelopmentWar) execution information?

Upvotes: 0

Views: 297

Answers (1)

Vampire
Vampire

Reputation: 38639

dependsOn = createDevelopmentWar results in a call to setDependsOn(createDevelopmentWar) which expects an Iterable that a task is not.

dependsOn createDevelopmentWar would result in a call to dependsOn(createDevelopmentWar) which expects a varargs parameter and thus sould add the task to the dependencies.

If you really want to replace all dependencies with this one dependency, you have to do it like dependsOn = [createDevelopmentWar].

Upvotes: 1

Related Questions