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

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

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

group = 'com.awslabs.aws.iot.greengrass.cdd'

description = """"""

def gradleDependencyVersion = '6.8.1'

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

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

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

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

def daggerVersion = '2.37'
def gsonVersion = '2.8.7'
def slf4jVersion = '2.0.0-alpha1'
def jcabiVersion = '0.19.0'
def jacksonVersion = '2.11.3'
def httpClientVersion = '4.5.13'
def awsLambdaJavaCoreVersion = '1.2.1'
def commonsIoVersion = '2.10.0'
def awsSdk2Version = '2.16.86'
def immutablesValueVersion = '2.8.9-ea-1'
def awsGreengrassCoreSdkJava = '1.4.1'
def vavrVersion = '0.10.2'

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

    // Immutables (requires annotation processing for code generation)
    annotationProcessor "org.immutables:value:$immutablesValueVersion"
    annotationProcessor "org.immutables:gson:$immutablesValueVersion"
    implementation "org.immutables:value:$immutablesValueVersion"

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

    compile githubJar('aws', 'aws-greengrass-core-sdk-java', awsGreengrassCoreSdkJava, 'GreengrassJavaSDK')
    compile "com.google.code.gson:gson:$gsonVersion"
    compile "org.slf4j:slf4j-log4j12:$slf4jVersion"
    compile "com.jcabi:jcabi-log:$jcabiVersion"
    compile "com.fasterxml.jackson.core:jackson-core:$jacksonVersion"
    compile "com.fasterxml.jackson.core:jackson-databind:$jacksonVersion"
    compile "org.apache.httpcomponents:httpclient:$httpClientVersion"
    compile "com.amazonaws:aws-lambda-java-core:$awsLambdaJavaCoreVersion"
    compile "software.amazon.awssdk:greengrass:$awsSdk2Version"
    compile "commons-io:commons-io:$commonsIoVersion"

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