plugins {
    id 'java-library'
    id 'maven-publish'
    id 'signing'
}

project.group = "de.codeshelf.consoleui"
project.version = "0.0.13"

java {
    withJavadocJar()
    withSourcesJar()
}


repositories {
    mavenCentral()
}

compileJava {
    sourceCompatibility = 1.8
    targetCompatibility = 1.8
}


dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.11'
    compile 'org.fusesource.jansi:jansi:1.11'
    compile 'jline:jline:2.14.6'
}

javadoc {
    options.encoding = 'UTF-8'
    if (JavaVersion.current().isJava9Compatible()) {
        options.addBooleanOption('html5', true)
    }
}


// Fat-jar
task fatJar(type: Jar, dependsOn: [':compileJava', ':processResources']) {
    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
    from sourceSets.main.output.classesDirs
    from sourceSets.main.output.resourcesDir
    project.archivesBaseName = project.name + '-all'
    manifest {
        attributes 'Implementation-Title': 'ConsoleUI',
                'Implementation-Version': project.version,
                'Main-Class': 'de.codeshelf.consoleui.Basic'

    }
}

task printEnv {
    println "username " + sonatypeUsername
}

publishing {
    repositories {
        mavenLocal {
            // change URLs to point to your repos, e.g. http://my.org/repo
            def releasesRepoUrl = "$buildDir/repos/releases"
            def snapshotsRepoUrl = "$buildDir/repos/snapshots"
            url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
        }
        mavenCentral {
            // change URLs to point to your repos, e.g. http://my.org/repo
            def releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
            def snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots/"
            url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
            credentials {
                username = sonatypeUsername
                password = sonatypePassword
            }
        }
    }

    publications {
        consoleUI(MavenPublication) {
            from components.java
            pom {
                name = 'ConsoleUI'
                description = 'Library for Ansi-Console user interaction'
                url = 'https://github.com/awegmann/consoleui/'

                licenses {
                    license {
                        name = 'The Apache License, Version 2.0'
                        url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                    }
                }
                developers {
                    developer {
                        id = "an10nn";
                        name = "Andreas Wegmann";
                        email = "andreas.we9mann@gmail.com";
                    }
                }
                scm {
                    connection = 'scm:git:git://github.com/awegmann/consoleui.git'
                    developerConnection = 'scm:git:ssh://git@github.com:awegmann/consoleui.git'
                    url = 'https://github.com/awegmann/consoleui/'
                }
            }
        }
    }
}

signing {
    sign publishing.publications.consoleUI
}
