// This script exists just to allow bootstrapping the gradle plugins if maven central or jcenter are unavailable
// or if you are developing these plugins. See the readme for more information.

buildscript {
    // For sharing constants between builds
    Properties constants = new Properties()
    file("$projectDir/../constants.properties").withInputStream { constants.load(it) }

    // If you bump this version you must re-bootstrap the codebase. See the README for more information.
    ext {
        gradle_plugins_version = constants.getProperty("gradlePluginsVersion")
        bouncycastle_version = constants.getProperty("bouncycastleVersion")
        typesafe_config_version = constants.getProperty("typesafeConfigVersion")
        jsr305_version = constants.getProperty("jsr305Version")
        kotlin_version = constants.getProperty("kotlinVersion")
        artifactory_plugin_version = constants.getProperty('artifactoryPluginVersion')
        snake_yaml_version = constants.getProperty('snakeYamlVersion')
        assertj_version = '3.8.0'
        junit_version = '4.12'
    }

    repositories {
        mavenLocal()
        jcenter()
    }

    dependencies {
        classpath "net.corda.plugins:publish-utils:$gradle_plugins_version"
        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "org.jfrog.buildinfo:build-info-extractor-gradle:$artifactory_plugin_version"
    }
}

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

allprojects {
    version gradle_plugins_version
    group 'net.corda.plugins'
}

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 = ['cordformation', 'quasar-utils', 'cordform-common', 'api-scanner', 'cordapp']
    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 = 'https://ci-artifactory.corda.r3cev.com/artifactory'
        repository {
            repoKey = 'corda-dev'
            username = 'teamcity'
            password = System.getenv('CORDA_ARTIFACTORY_PASSWORD')
        }

        defaults {
            // Publish utils does not have a publish block because it would be circular for it to apply it's own
            // extensions to itself
            if(project.name == 'publish-utils') {
                publications('publishUtils')
            // Root project applies the plugin (for this block) but does not need to be published
            } else if(project != rootProject) {
                publications(project.extensions.publish.name())
            }
        }
    }
}