plugins {
    id 'groovy-gradle-plugin'
}

Properties constants = new Properties()
file("$rootDir/../constants.properties").withInputStream { constants.load(it) }

def internalPublishVersion = constants.getProperty('internalPublishVersion')
def artifactoryContextUrl = constants.getProperty('artifactoryContextUrl')

repositories {
    def cordaUseCache = System.getenv("CORDA_USE_CACHE")
    if (cordaUseCache != null) {
        maven {
            url = "${artifactoryContextUrl}/${cordaUseCache}"
            name = "R3 Maven remote repositories"
            authentication {
                basic(BasicAuthentication)
            }
            credentials {
                username = findProperty('cordaArtifactoryUsername') ?: System.getenv('CORDA_ARTIFACTORY_USERNAME')
                password = findProperty('cordaArtifactoryPassword') ?: System.getenv('CORDA_ARTIFACTORY_PASSWORD')
            }
            metadataSources {
                mavenPom()
                artifact()
                ignoreGradleMetadataRedirection()
            }
        }
    } else {
        maven {
            url "${artifactoryContextUrl}/engineering-tools-maven"
            authentication {
                basic(BasicAuthentication)
            }
            credentials {
                username = findProperty('cordaArtifactoryUsername') ?: System.getenv('CORDA_ARTIFACTORY_USERNAME')
                password = findProperty('cordaArtifactoryPassword') ?: System.getenv('CORDA_ARTIFACTORY_PASSWORD')
            }
            content {
                includeGroupByRegex 'com\\.r3\\.internal(\\..*)?'
            }
        }
        gradlePluginPortal()
    }
}

dependencies {
    implementation "com.github.docker-java:docker-java:$constants.dockerJavaVersion"
    implementation "com.github.docker-java:docker-java-transport-httpclient5:$constants.dockerJavaVersion"
    implementation "org.jooq:joor:$constants.joorVersion"

    if (System.getenv('CORDA_ARTIFACTORY_USERNAME') != null || project.hasProperty('cordaArtifactoryUsername')) {
        implementation "com.r3.internal.gradle.plugins:publish:$internalPublishVersion"
    }
}
