如何在Gradle中命名构建工件的任意名称?

时间:2018-07-19 16:24:05

标签: amazon-web-services gradle aws-lambda build.gradle

按照本指南将AWS Lambdas构建为ZIP文件,以便可以对其进行部署:https://docs.aws.amazon.com/lambda/latest/dg/create-deployment-pkg-zip-java.html

在我的根build.gradle中,我现在有这个(它直接从指南中获取lambdaZip任务):

plugins {
    id 'my-company.plugin-plugin' version '1.0.0-rc.132'
}

dependencies {
    resolutionRules group:'my-company', name: 'gradle-resolution-rules', version: '12.0.0'
}

group = 'my-company'

subprojects {
    group = parent.group

    sourceCompatibility = 1.8
    targetCompatibility = 1.8

    dependencies {
        ...deps...
    }

    idea.module.iml {
        beforeMerged { module ->
            module.dependencies.clear()
        }
    }

    ...more unrelated stuff...

    task lambdaZip(type: Zip) {
        from compileJava
        from compileGroovy
        from processResources
        into('lib') {
            from configurations.runtime
        }
    }
}

构建Lambda(例如./gradlew :lambda:accountworker:lambdaZip)时,将导致创建此文件:

/myproject/lambda/accountworker/build/distributions/accountworker-<PROJECT-VERSION_NUMBER_HERE>.zip

这是我的问题-我希望将构建的.zip文件命名为accountworker-LATEST.zip,而不是项目的版本号。我不能将project.version的数字指定为LATEST,因为这将完全破坏我的构建系统的其他部分。

我该怎么做?

1 个答案:

答案 0 :(得分:0)

Doh,只需指定存档名称...

https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/bundling/AbstractArchiveTask.html#setArchiveName-java.lang.String-

task lambdaZip(type: Zip) {
    from compileJava
    from compileGroovy
    from processResources
    into('lib') {
        from configurations.runtime
    }
    archiveName = "${baseName}-LATEST.zip"
}