build.gradle

The build.gradle for a typical Kotlin Lambda function is as shown in the following code block:

apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'idea'
apply plugin: 'kotlin'
apply plugin: 'com.github.johnrengelman.shadow'


group = 'com.packt.serverless.kotlin'
version = '1.0.0'

description = """Simple Greeter lambda function"""


sourceCompatibility = 1.8
targetCompatibility = 1.8
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}

buildscript {
repositories {
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.51"
classpath "com.github.jengelman.gradle.plugins:shadow:2.0.1"
}
}



repositories {
maven { url "http://repo.maven.apache.org/maven2" }
}

dependencies {
compile group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib', version: '1.1.51'

compile group: 'com.amazonaws', name: 'aws-lambda-java-core', version:'1.1.0'
compile group: 'com.amazonaws', name: 'aws-lambda-java-log4j2', version:'1.0.0'
compile group: 'com.amazonaws', name: 'aws-lambda-java-events', version:'2.0.1'

compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version:'2.8.5'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version:'2.8.5'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version:'2.8.5'
}

shadowJar{
mergeServiceFiles('META-INF/spring.*')
exclude "META-INF/*.SF"
exclude "META-INF/*.DSA"
exclude "META-INF/*.RSA"
exclude "META-INF/LICENSE"
archiveName = "greeter-${version}.${extension}"
}

Here are a few points to know about the preceding code:

  • We use the Gradle Shadow plugin to get a .jar deployment package with all its dependencies
  • We change the configuration of the shadow task to yield a better-named uber jar, for example, greeter-1.0.0.jar