Search code examples
gradleaws-lambda

Package Gradle as Zip


How do I update this Gradle code into the Gradle(Kotlin) version? I want to build my Java application so it can be deployed on AWS Lambda.

task packageJar(type: Zip) {
    into('lib') {
        from(jar)
        from(configurations.runtimeClasspath)
    }
}

build.dependsOn packageJar

The following code snippet is from https://docs.aws.amazon.com/lambda/latest/dg/java-package.html


Solution

  • How about this?

    plugins {
        java
    }
    
    tasks.register<Zip>("packageJar") {
        into("lib") {
            from(tasks.jar)
            from(configurations.runtimeClasspath)
        }
    }
    
    tasks.build {
        dependsOn("packageJar")
    }
    

    I've added the plugins block because otherwise tasks.jar and configurations.runtimeClasspth are not available.