将战争任务连接到货物部署任务

时间:2017-01-25 09:45:38

标签: gradle

我已经创建了一个gradle脚本,以便使用cargo插件在容器上部署可部署的脚本:

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
    }
}

尽管如此,我还是根据其范围创建了几个任务来创建自定义war文件:

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 {
       ...
    }
}

我希望关联deployDev个任务,选择在createDevelopmentWar上生成的战争工件。

我尝试将dependsOn属性设置为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  <<<<<<<<<<<<<<<<<
    }
}

尽管如此,请告诉我这条消息:

  
      
  • 出了什么问题:   评估根项目&webapi&#39;时出现问题。   无法投射对象&#39;:createDevelopmentWar&#39;&#39;与班级&#39; org.gradle.api.tasks.bundling.War_Decorated&#39; class&#39; java.lang.Iterable   &#39;
  •   

我还尝试将dependsOn设置为war任务,但消息是相同的。

修改

有一次,我改变了dependsOn = [createDevelopmentWar]的语法,我正面临另一个麻烦:

它告诉我这个消息:

  

任务执行失败&#39;:deployDevWildfly10&#39;。   可部署的D:\ projects \ living \ platform \ webapi \ build \ libs \ webapi-dev-89c157a-dirty.war不存在

它试图从build\libs\获取神器。然而,战争工件已在destinationDir = file("$buildDir/dist")

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

我如何设置货物从以前的war type task(createDevelopmentWar)执行信息中选取工件?

1 个答案:

答案 0 :(得分:1)

dependsOn = createDevelopmentWar会调用setDependsOn(createDevelopmentWar),要求Iterable任务不是。

dependsOn createDevelopmentWar会导致调用dependsOn(createDevelopmentWar),它需要一个varargs参数,因此可以将任务添加到依赖项中。

如果你真的想用这个依赖项替换所有依赖项,你必须像dependsOn = [createDevelopmentWar]那样。