buildscript {
    ext {
        corda_djvm_version = '5.0-SNAPSHOT'
        artifactory_contextUrl = 'https://software.r3.com/artifactory'
    }

    repositories {
        mavenCentral()
    }

    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

plugins {
    id 'net.corda.plugins.publish-utils' version '4.0.44' apply false
    id 'com.github.johnrengelman.shadow' version '5.0.0' apply false
    id 'com.jfrog.artifactory' version '4.7.3' apply false
    id 'com.jfrog.bintray' version '1.4' apply false
    id 'com.gradle.build-scan' version '2.2.1'
}

import static org.gradle.api.JavaVersion.*
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

subprojects {
    group 'net.corda'
    version corda_djvm_version

    repositories {
        mavenCentral()
        jcenter()
    }

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

    tasks.withType(KotlinCompile) {
        kotlinOptions {
            languageVersion = '1.2'
            apiVersion = '1.2'
            jvmTarget = VERSION_1_8
            javaParameters = true   // Useful for reflection.
            freeCompilerArgs = ['-Xjvm-default=enable']
        }
    }

    tasks.withType(Jar) { task ->
        manifest {
            attributes('Corda-Vendor': 'Corda Open Source')
            attributes('Automatic-Module-Name': "net.corda.${task.project.name.replaceAll('-', '.')}")
        }
    }

    tasks.withType(Test) {
        useJUnitPlatform()

        // Prevent the project from creating temporary files outside of the build directory.
        systemProperty 'java.io.tmpdir', buildDir.absolutePath
    }
}

apply plugin: 'net.corda.plugins.publish-utils'
apply plugin: 'com.jfrog.artifactory'

bintrayConfig {
    user = System.getenv('CORDA_BINTRAY_USER')
    key = System.getenv('CORDA_BINTRAY_KEY')
    repo = 'corda'
    org = 'r3'
    licenses = ['Apache-2.0']
    vcsUrl = 'https://github.com/corda/corda'
    projectUrl = 'https://github.com/corda/corda'
    gpgSign = true
    gpgPassphrase = System.getenv('CORDA_BINTRAY_GPG_PASSPHRASE')
    publications = [
        'corda-djvm',
        'corda-djvm-cli'
    ]
    license {
        name = 'Apache-2.0'
        url = 'https://www.apache.org/licenses/LICENSE-2.0'
        distribution = 'repo'
    }
    developer {
        id = 'R3'
        name = 'R3'
        email = 'dev@corda.net'
    }
}

artifactory {
    publish {
        contextUrl = artifactory_contextUrl
        repository {
            repoKey = 'corda-dev'
            username = System.getenv('CORDA_ARTIFACTORY_USERNAME')
            password = System.getenv('CORDA_ARTIFACTORY_PASSWORD')
        }

        defaults {
            // The root project has applied 'publish-utils' but has nothing to publish.
            if (project != rootProject) {
                publications(project.extensions.publish.name())
            }
        }
    }
}

wrapper {
    gradleVersion = "5.4.1"
    distributionType = Wrapper.DistributionType.ALL
}

buildScan {
    termsOfServiceUrl = 'https://gradle.com/terms-of-service'
    termsOfServiceAgree = 'yes'
}