buildscript {
    repositories {
        mavenCentral()
        // Needed only for SNAPSHOT versions
        maven { url "http://oss.sonatype.org/content/repositories/snapshots/" }
    }
    dependencies {
        classpath "io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.11.0"
    }
}

version = '0.3.4-SNAPSHOT'

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'maven'
apply plugin: 'signing'
apply plugin: 'io.codearte.nexus-staging'

repositories {
    mavenCentral()
}

group = 'org.fxmisc.wellbehaved'
project.archivesBaseName = 'wellbehavedfx'

sourceCompatibility = '1.8'
targetCompatibility = '1.8'

dependencies {
    testCompile group: 'junit', name: 'junit', version: '[4.0,)'
    testCompile group: 'org.hamcrest', name: 'hamcrest-junit', version: '2.0.0.0'

    // TestFX dependencies
    testCompile ("org.testfx:testfx-junit:4.0.8-alpha") {
        exclude(group: "junit", module: "junit")
    }
    testCompile "org.testfx:openjfx-monocle:8u76-b04"
}

javadoc {
    // ignore missing Javadoc comments or tags
    options.addStringOption('Xdoclint:all,-missing', '-quiet')

    // support for JavaFX properties
    options.addBooleanOption('javafx', true);

    // resolve links to Java and JavaFX Javadocs
    options.links = [
            'http://docs.oracle.com/javase/8/docs/api/',
            'http://docs.oracle.com/javase/8/javafx/api/'
    ]
}

task getVersion {
    doLast {
        println version
    }
}

task javadocJar(type: Jar, dependsOn: javadoc) {
    classifier = 'javadoc'
    from 'build/docs/javadoc'
}

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

artifacts {
    archives jar

    archives javadocJar
    archives sourcesJar
}

signing {
    sign configurations.archives
}

signArchives.onlyIf {
    project.hasProperty('signing.keyId') && project.hasProperty('signing.password') && project.hasProperty('signing.secretKeyRingFile')
}

def doUploadArchives = project.hasProperty('sonatypeUsername') && project.hasProperty('sonatypePassword')

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

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

            snapshotRepository(url: 'https://oss.sonatype.org/content/repositories/snapshots') {
                authentication(userName: sonatypeUsername, password: sonatypePassword)
            }

            pom.project {
                name 'WellBehavedFX'
                description 'Composable event handlers and skin skeletons for JavaFX controls.'
                url 'http://www.fxmisc.org/wellbehaved/'
                packaging 'jar'
                licenses {
                    license {
                        name 'The BSD 2-Clause License'
                        url 'http://opensource.org/licenses/BSD-2-Clause'
                        distribution 'repo'
                    }
                }
                scm {
                    url 'scm:git@github.com:FXMisc/WellBehavedFX.git'
                    connection 'scm:git@github.com:FXMisc/WellBehavedFX.git'
                    developerConnection 'scm:git@github.com:FXMisc/WellBehavedFX.git'
                }
                developers {
                    developer {
                        name 'Tomas Mikula'
                    }
                }
            }
        }
    }
}

uploadArchives.onlyIf { doUploadArchives }

nexusStaging {
    packageGroup = "org.fxmisc.wellbehaved"
}
