plugins {
    id 'java'
    id 'application'
    id 'idea'

    // Creates fat JAR
    id 'com.github.johnrengelman.shadow' version '7.0.0'

    // Adds dependencyUpdates task
    id 'com.github.ben-manes.versions' version '0.39.0'
}

distZip.enabled = shadowDistZip.enabled = false
distTar.enabled = shadowDistTar.enabled = false

// Required by shadow but not necessary
mainClassName = 'not-necessary'

group = 'CDDDockerJava'
version = '1.0-SNAPSHOT'

description = """"""

sourceCompatibility = 1.8
targetCompatibility = 1.8

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

def gradleDependencyVersion = '6.8.1'

wrapper {
    gradleVersion = gradleDependencyVersion
    distributionType = Wrapper.DistributionType.ALL
}

repositories {
    mavenCentral()
    maven { url "https://plugins.gradle.org/m2/" }
    maven { url 'https://jitpack.io' }
}

// Guidance from: https://stackoverflow.com/questions/23446233/compile-jar-from-url-in-gradle
def githubJar = { organization, module, revision, name ->
    File file = new File("$buildDir/libs/${name}.jar")
    file.parentFile.mkdirs()
    if (!file.exists()) {
        def url = "https://github.com/$organization/$module/raw/v$revision/sdk/GreengrassJavaSDK.jar"
        new URL(url).withInputStream { downloadStream ->
            file.withOutputStream { fileOut ->
                fileOut << downloadStream
            }
        }
    }
    files(file.absolutePath)
}

def awsGreengrassCoreSdkJava = '1.4.1'
def cddVersion = '0.8.74'
def gsonVersion = '2.8.7'
def slf4jVersion = '2.0.0-alpha1'
def awsSdkVersion = '1.12.8'
def jacksonVersion = '2.11.3'
def awsLambdaJavaCoreVersion = '1.2.1'
def immutablesValueVersion = '2.8.9-ea-1'
def dockerJavaVersion = '3.2.10'
def vavrVersion = '0.10.3'
def daggerVersion = '2.37'

dependencies {
    implementation githubJar('aws', 'aws-greengrass-core-sdk-java', awsGreengrassCoreSdkJava, 'GreengrassJavaSDK')
    annotationProcessor "org.immutables:value:$immutablesValueVersion"
    compile "org.immutables:value:$immutablesValueVersion"

    compile "com.github.aws-samples:aws-greengrass-lambda-functions:$cddVersion"

    // Dagger code generation
    annotationProcessor "com.google.dagger:dagger-compiler:$daggerVersion"

    // Dependency injection with Dagger
    compile "com.google.dagger:dagger:$daggerVersion"

    compile "com.google.code.gson:gson:$gsonVersion"
    compile "org.slf4j:slf4j-jdk14:$slf4jVersion"
    compile "com.amazonaws:aws-java-sdk-core:$awsSdkVersion"
    compile "com.fasterxml.jackson.core:jackson-core:$jacksonVersion"
    compile "com.fasterxml.jackson.core:jackson-databind:$jacksonVersion"
    compile "com.amazonaws:aws-lambda-java-core:$awsLambdaJavaCoreVersion"

    compile "com.github.docker-java:docker-java:$dockerJavaVersion"
    compile "com.amazonaws:aws-java-sdk-ecr:$awsSdkVersion"

    compile "io.vavr:vavr:$vavrVersion"
}
