configurations {
    utils { }
    controller {
        transitive = false
    }
    gists_api {
        transitive = false
    }
}

dependencies {
    utils project(":utils:redis-client")
}

task copyRedisClient(type: Copy) {
    dependsOn(':utils:redis-client:build')
    from configurations.utils
    into "libs" 
    rename("redis-client-" + project.version + ".jar", "redis-client.jar")
}

def inputFiles = [
    project.file("Ballerina.toml"),
    project.file("Ballerina.lock"),
    project.file("src")
]

task clean(type: Delete) {
   delete 'target', 'libs'
   followSymlinks = true
}

def env = System.getenv()
def gcpProjectID = env["BPG_GCP_PROJECT_ID"]

task build(type: Exec) {
    dependsOn clean
    dependsOn copyRedisClient
    inputs.files(inputFiles)
    outputs.cacheIf { true }
    outputs.dir("target")
    commandLine 'ballerina', 'build', '-a'
    ignoreExitValue false
}

artifacts.add("controller", project.file("target/bin/playground_controller.jar"))
artifacts.add("gists_api", project.file("target/bin/playground_gists.jar"))
