【问题标题】:Connect war task to cargo deploy task将战争任务连接到货物部署任务
【发布时间】:2017-01-25 09:45:38
【问题描述】:

我创建了一个 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
    }
}

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

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

尽管如此,gradle 它给我这个消息:

  • 出了什么问题: 评估根项目“webapi”时出现问题。 无法将具有类“org.gradle.api.tasks.bundling.War_Decorated”的对象“任务”:createDevelopmentWar 转换为类“java.lang.Iterable” '

我也尝试将dependsOn 设置为war 任务,但是消息是一样的。

编辑

有一次,我更改了dependsOn = [createDevelopmentWar] 的语法,我又遇到了另一个麻烦:

它让我收到这条消息:

任务“:deployDevWildfly10”执行失败。 可部署的 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 {
           ...
        }
    }

如何设置 cargo 从之前的 war type task(createDevelopmentWar) 执行信息中提取工件?

【问题讨论】:

    标签: gradle


    【解决方案1】:

    dependsOn = createDevelopmentWar 导致对 setDependsOn(createDevelopmentWar) 的调用,它期望 Iterable 不是任务。

    dependsOn createDevelopmentWar 将导致对 dependsOn(createDevelopmentWar) 的调用,该调用需要一个可变参数,因此应该将任务添加到依赖项中。

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

    【讨论】:

    • 谢谢@Vampire。我现在收到另一条消息。它正在从不正确的文件夹中提取工件。我已经编辑了帖子。有什么想法吗?
    • 遵循您正在使用的插件的文档。默认情况下,它会从应用的warear 任务中自动检测可部署文件,但在您的情况下,这不适用,因此它找不到它尝试部署的文件。用你的自定义战争定义一个可部署的,你会没事的。如果插件开发正确,并且您在可部署闭包中使用 file(createDevelopmentWar) 作为文件,您甚至可以不显式指定 dependsOn,但无论如何都应该隐式指定。
    • 我能理解你的意思。不过,我不太了解如何更改脚本(我是使用 gradle 的新手)。你能给我提供一些有用的代码来说明如何获得它吗?
    • 我的意思是如何在我的deployDev-like 任务中创建deployable。否则,我怎么能避免使用dependsOn 并创建一种隐式方式来做到这一点?
    • 正如我所说,查看您使用的插件的文档,在您的情况下为github.com/bmuschko/gradle-cargo-plugin。我帮不上什么忙,因为我不使用那个插件。我只是快速浏览了文档和代码,以尽可能好地回答您的问题,而不会深入研究。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-13
    • 2011-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多