buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        classpath 'com.github.ben-manes:gradle-versions-plugin:0.12.0'
    }
}

plugins {
    id 'nebula.provided-base' version '3.0.3'
    id 'net.researchgate.release' version '2.4.0'
}

group 'com.dimafeng'

apply plugin: 'scala'
apply plugin: 'nebula.provided-base'
apply plugin: 'com.github.ben-manes.versions'
apply plugin: 'maven'
apply plugin: 'signing'


sourceCompatibility = 1.8

def scala = project.hasProperty("scala") ? project.getProperty("scala") : scalaVersion
println("Run with scala: $scala")
def scalaPostfix = scala.substring(0, scala.lastIndexOf("."))

def artifactId = "testcontainers-scala_$scalaPostfix"

repositories {
    mavenCentral()
}

dependencies {
    compile("org.testcontainers:testcontainers:$testcontainersVersion")
    provided("org.scala-lang:scala-library:$scala",
            "org.seleniumhq.selenium:selenium-java:$seleniumVersion",
            "org.testcontainers:selenium:$testcontainersVersion",
            "org.slf4j:slf4j-simple:$slf4jVersion",
            "org.scalatest:scalatest_$scalaPostfix:$scalaTestVersion",
            "org.testcontainers:mysql:$testcontainersVersion")

    testCompile("junit:junit:4.12",
            "org.testcontainers:selenium:$testcontainersVersion",
            "mysql:mysql-connector-java:$mysqlConnectorVersion",
            "org.mockito:mockito-all:$mockitoVersion")
}

test {
    exclude 'com/dimafeng/testcontainers/integration/**'
}

task integrationTest(type: Test) {
    include 'com/dimafeng/testcontainers/integration/**'
}

task sourcesJar(type: Jar) {
    classifier = 'sources'
    from sourceSets.main.allSource
}

task javadocJar(type: Jar) {
    classifier = 'javadoc'
    from scaladoc
}

artifacts {
    archives javadocJar, sourcesJar
}

signing {
    sign configurations.archives
}

ext.ossrhUsernameValue = project.hasProperty("ossrhUsername") ? project.getProperty("ossrhUsername") : ""
ext.ossrhPasswordValue = project.hasProperty("ossrhPassword") ? project.getProperty("ossrhPassword") : ""

/**
 * Skip signArchives for travis-ci
 */
tasks.each { task ->
    if (!project.hasProperty("ossrhPassword") && "signArchives".equals(task.name)) {
        task.enabled = false
    }
}

uploadArchives {
    repositories {
        mavenDeployer {
            beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }

            repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
                authentication(userName: ossrhUsernameValue, password: ossrhPasswordValue)
            }

            snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
                authentication(userName: ossrhUsernameValue, password: ossrhPasswordValue)
            }

            pom.artifactId = artifactId

            pom.project {
                name artifactId
                packaging 'jar'
                description 'Scala wrapper for testcontainers-java'
                url 'https://github.com/dimafeng/testcontainers-scala'

                scm {
                    connection 'scm:git:git@github.com:dimafeng/testcontainers-scala.git'
                    developerConnection 'scm:git:git@github.com:dimafeng/testcontainers-scala.git'
                    url 'git@github.com:dimafeng/testcontainers-scala.git'
                }

                licenses {
                    license {
                        name 'The MIT License (MIT)'
                        url 'https://opensource.org/licenses/MIT'
                    }
                }

                developers {
                    developer {
                        name 'Dmitry Fedosov'
                        email 'dimafeng@gmail.com'
                    }
                }
            }
        }
    }
}