buildscript {
    repositories {
        mavenCentral()
        maven { url = "https://oss.sonatype.org/content/repositories/snapshots/" }
        jcenter()
    }

    configurations.all {
        resolutionStrategy {
            force 'com.google.guava:guava:18.0'
        }
    }

    dependencies {
        classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:3.0.1'
    }
}

if (!project.hasProperty("artifactory_contextUrl")) ext.artifactory_contextUrl = "http://localhost"
if (!project.hasProperty("artifactory_user")) ext.artifactory_user = "guest"
if (!project.hasProperty("artifactory_password")) ext.artifactory_password = ""

subprojects {
    apply plugin: 'java'
    apply plugin: 'maven'
    apply plugin: 'checkstyle'
    apply plugin: 'com.jfrog.artifactory-upload'

    group = 'com.sk89q.intake'
    version = '4.2-SNAPSHOT'

    checkstyle.configFile = new File(rootProject.projectDir, "config/checkstyle/checkstyle.xml")

    sourceCompatibility = 1.6
    targetCompatibility = 1.6

    repositories {
        maven { url "https://maven.enginehub.org/repo/" }
        mavenCentral()
        maven { url "http://repo.maven.apache.org/maven2" }
    }

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

    task javadocJar(type: Jar, dependsOn: javadoc) {
        classifier = 'javadoc'
        from javadoc.destinationDir
    }

    artifacts {
        archives jar
        archives sourcesJar
        archives javadocJar
    }

    build.dependsOn(checkstyleMain)
    build.dependsOn(checkstyleTest)
    build.dependsOn(sourcesJar)
    build.dependsOn(javadocJar)

    artifactory {
        contextUrl = "${artifactory_contextUrl}"
        publish {
            repository {
                repoKey = project.version.contains("SNAPSHOT") ? 'libs-snapshot-local' : 'libs-release-local'
                username = "${artifactory_user}"
                password = "${artifactory_password}"
                maven = true
                
            }
        }

        resolve {
            repository {
                repoKey = 'repo'
                username = "${artifactory_user}"
                password = "${artifactory_password}"
                maven = true
            }
        }
    }
}
