repositories {
    maven {
        url "$artifactory_contextUrl/corda-dependencies"
    }
}

ext {
    jdk_home = "$projectDir/jdk".toString()
    rt_jar = "$jdk_home/jre/lib/rt.jar".toString()
}

configurations {
    jdk
}

dependencies {
    jdk "net.corda:deterministic-rt:$deterministic_rt_version:api"
}

def copyJdk = tasks.register('copyJdk', Copy) {
    outputs.dir jdk_home

    from(configurations.jdk) {
        rename 'deterministic-rt-(.*).jar', 'rt.jar'
    }
    into "$jdk_home/jre/lib"

    doLast {
        def eol = System.lineSeparator()
        file("$jdk_home/release").write "JAVA_VERSION=\"1.8.0_172\"$eol"
        mkdir "$jdk_home/bin"
        file("$jdk_home/bin/javac").with {
            write "#!/bin/sh\necho \"javac 1.8.0_172\"\n"
            setExecutable true, false
            return
        }
    }
}

assemble.dependsOn copyJdk
tasks.named('jar', Jar)  {
    enabled = false
}

artifacts {
    jdk file: file(rt_jar), type: 'jar', builtBy: copyJdk
}
