buildscript {
    ext.corda_release_group = 'net.corda'
    ext.corda_release_version = '3.2-corda'
    ext.corda_gradle_plugins_version = '3.1.0'
    ext.kotlin_version = '1.1.60'
    ext.junit_version = '4.12'
    ext.quasar_version = '0.7.9'

    repositories {
        mavenLocal()
        mavenCentral()
        jcenter()
    }

    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "net.corda.plugins:cordapp:$corda_gradle_plugins_version"
        classpath "net.corda.plugins:cordformation:$corda_gradle_plugins_version"
        classpath "net.corda.plugins:quasar-utils:$corda_gradle_plugins_version"
    }
}

allprojects {
    repositories {
        mavenLocal()
        jcenter()
        mavenCentral()
        maven { url 'https://ci-artifactory.corda.r3cev.com/artifactory/corda' }
        maven { url 'https://jitpack.io' }
    }
}

apply plugin: 'kotlin'
apply plugin: 'net.corda.plugins.cordapp'
apply plugin: 'net.corda.plugins.cordformation'
apply plugin: 'net.corda.plugins.quasar-utils'

sourceSets {
    main {
        resources {
            srcDir "config/dev"
        }
    }
    test {
        resources {
            srcDir "config/test"
        }
    }
    integrationTest {
        kotlin {
            compileClasspath += main.output + test.output
            runtimeClasspath += main.output + test.output
            srcDir file('src/integration-test/kotlin')
        }
    }
}

configurations {
    integrationTestCompile.extendsFrom testCompile
    integrationTestRuntime.extendsFrom testRuntime
}

dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
    testCompile "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
    testCompile "junit:junit:$junit_version"

    // Corda integration dependencies
    cordaCompile "$corda_release_group:corda-core:$corda_release_version"
    cordaCompile "$corda_release_group:corda-finance:$corda_release_version"
    cordaCompile "$corda_release_group:corda-jackson:$corda_release_version"
    cordaCompile "$corda_release_group:corda-rpc:$corda_release_version"
    cordaCompile "$corda_release_group:corda-node-api:$corda_release_version"
    cordaCompile "$corda_release_group:corda-webserver-impl:$corda_release_version"
    cordaRuntime "$corda_release_group:corda:$corda_release_version"
    cordaRuntime "$corda_release_group:corda-webserver:$corda_release_version"

    testCompile "$corda_release_group:corda-node-driver:$corda_release_version"

    // CorDapp dependencies
    // Specify your CorDapp's dependencies below, including dependent CorDapps.
    cordapp project(":cordapp")
}

task integrationTest(type: Test, dependsOn: []) {
    testClassesDirs = sourceSets.integrationTest.output.classesDirs
    classpath = sourceSets.integrationTest.runtimeClasspath
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
    kotlinOptions {
        languageVersion = "1.1"
        apiVersion = "1.1"
        jvmTarget = "1.8"
        javaParameters = true   // Useful for reflection.
    }
}

task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['jar']) {
    directory "./build/nodes"
    node {
        name "O=Notary,L=London,C=GB"
        notary = [validating : false]
        p2pPort 10002
        rpcSettings {
            address("localhost:10003")
            adminAddress("localhost:10043")
        }
        cordapps = [
                "$project.group:cordapp-contracts-states:$project.version",
                "$project.group:cordapp:$project.version"
        ]
    }
    node {
        name "O=ContosoLtd,L=Seatle,C=US"
        p2pPort 10005
        rpcSettings {
            address("localhost:10006")
            adminAddress("localhost:11006")
        }
        webPort 10007
        cordapps = [
                "$project.group:cordapp-contracts-states:$project.version",
                "$project.group:cordapp:$project.version"
        ]
        rpcUsers = [[ user: "user1", "password": "test", "permissions": ["ALL"]]]
    }
    node {
        name "O=WorldWideImporters,L=Memphhsis,C=US"
        p2pPort 10008
        rpcSettings {
            address("localhost:10009")
            adminAddress("localhost:11009")
        }
        webPort 10010
        cordapps = [
                "$project.group:cordapp-contracts-states:$project.version",
                "$project.group:cordapp:$project.version"
        ]
        rpcUsers = [[ user: "user1", "password": "test", "permissions": ["ALL"]]]
    }
    node {
        name "O=NorthwindTraders,L=Copenhagen,C=DK"
        p2pPort 10011
        rpcSettings {
            address("localhost:10012")
            adminAddress("localhost:11012")
        }
        webPort 10013
        cordapps = [
                "$project.group:cordapp-contracts-states:$project.version",
                "$project.group:cordapp:$project.version"
        ]
        rpcUsers = [[ user: "user1", "password": "test", "permissions": ["ALL"]]]
    }
    node {
        name "O=WoodgroveBank,L=london,C=GB"
        p2pPort 10014
        rpcSettings {
            address("localhost:10015")
            adminAddress("localhost:11005")
        }
        webPort 10016
        cordapps = [
                "$project.group:cordapp-contracts-states:$project.version",
                "$project.group:cordapp:$project.version"
        ]
        rpcUsers = [[ user: "user1", "password": "test", "permissions": ["ALL"]]]
    }
    node {
        name "O=Device01,L=london,C=GB"
        p2pPort 10017
        rpcSettings {
            address("localhost:10018")
            adminAddress("localhost:11008")
        }
        webPort 10019
        cordapps = [
                "$project.group:cordapp-contracts-states:$project.version",
                "$project.group:cordapp:$project.version"
        ]
        rpcUsers = [[ user: "user1", "password": "test", "permissions": ["ALL"]]]
    }
    node {
        name "O=Device02,L=Shanghai,C=CN"
        p2pPort 10020
        rpcSettings {
            address("localhost:10021")
            adminAddress("localhost:11021")
        }
        webPort 10022
        cordapps = [
                "$project.group:cordapp-contracts-states:$project.version",
                "$project.group:cordapp:$project.version"
        ]
        rpcUsers = [[ user: "user1", "password": "test", "permissions": ["ALL"]]]
    }
    node {
        name "O=TasmanianTraders,L=Hobart,C=AU"
        p2pPort 10023
        rpcSettings {
            address("localhost:10024")
            adminAddress("localhost:11025")
        }
        webPort 10025
        cordapps = [
                "$project.group:cordapp-contracts-states:$project.version",
                "$project.group:cordapp:$project.version"
        ]
        rpcUsers = [[user: "user1", "password": "test", "permissions": ["ALL"]]]
    }
}


task runTemplateClient(type: JavaExec) {
    classpath = sourceSets.main.runtimeClasspath
    main = 'com.template.ClientKt'
    args 'localhost:10006'
}
