apply plugin: 'scala'
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'signing'

version = '0.1.0.0'
def scalaVersion = '2.10.3'

configurations {
    deployerJars
}

uploadArchives {
    signing {
        sign configurations.archives
        repositories.mavenDeployer {
            beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
            pom.groupId = 'ly.stealth'
            pom.artifactId = 'scala-kafka'
            pom.version = version
            pom.project {
                name 'Scala Kafka'
                packaging 'jar'
                url 'http://github.com/elodina/scala-kafka'
                description 'Quick up and running using Scala for Apache Kafka'
                scm {
                    url 'http://github.com/elodina/scala-kafka'
                    connection 'scm:https://github.com/elodina/scala-kafka'
                    developerConnection 'scm:git:git://github.com/elodina/scala-kafka'
                }
                licenses {
                    license {
                        name 'The Apache Software License, Version 2.0'
                        url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                        distribution 'repo'
                    }
                }
                developers {
                    developer {
                        id 'stealthly'
                        name 'Joe Stein'
                        email 'joe.stein@stealth.ly'
                    }
                }
            }
            configuration = configurations.deployerJars
            repository(url: "${mavenURL}") {
                authentication(userName: "${mavenUsername}", password: "${mavenPassword}")
            }
        }
    }
}

tasks.withType(ScalaCompile) { scalaCompileOptions.useAnt = false }

tasks.withType(ScalaDoc) {
    task srcJar(type:Jar) {
        classifier = 'sources'
        from '../LICENSE'
        from '../NOTICE'
        from sourceSets.main.scala
    }

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

    task docsJar(type: Jar, dependsOn: javadocJar) { }

    artifacts {
        archives srcJar
        archives javadocJar
    }
}

tasks.withType(ScalaCompile) { scalaCompileOptions.useAnt = false }

task specs(type: JavaExec, dependsOn: testClasses) {
    main = 'org.specs2.files'
    args = ['console']
    classpath sourceSets.main.runtimeClasspath
    classpath sourceSets.test.runtimeClasspath
    classpath configurations.testRuntime
    classpath configurations.runtime
}

task wrapper(type: Wrapper) {
    gradleVersion = '2.3'
}

task scalago(type: Jar) {
    dependsOn compileJava, compileScala, processResources, classes

    def mainClassName = "scalago.ScalaGoKafka"

    jar {
        doFirst {
            from(configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }) {
                exclude "META-INF/*.SF"
                exclude "META-INF/*.DSA"
                exclude "META-INF/*.RSA"
                exclude "org/apache/storm/*"
                exclude "defaults.yaml"
            }
        }
        manifest.attributes("Main-Class": mainClassName)
    }
}

test.dependsOn specs

repositories {
    mavenCentral()
    maven {
        url = 'http://repo.typesafe.com/typesafe/releases/'
        url = 'https://oss.sonatype.org/content/repositories/snapshots/'
        url = "http://packages.confluent.io/maven/"
    }
}

dependencies {
    compile "org.scala-lang:scala-compiler:$scalaVersion"
    compile 'org.scala-lang:scala-library:$scalaVersion'
    compile 'org.apache.kafka:kafka_2.10:0.8.2.1'
    compile 'com.101tec:zkclient:0.3'
    compile 'log4j:log4j:1.2.17'
    compile 'net.sf.jopt-simple:jopt-simple:4.5'
    compile 'org.apache.avro:avro:1.7.5'
    compile 'com.github.scopt:scopt_2.9.2:3.1.0'
    compile 'com.yammer.metrics:metrics-core:2.2.0'
    compile 'nl.grons:metrics-scala_2.9.2:3.0.3'
    compile group: 'com.typesafe.akka', name: 'akka-actor_2.10', version: '2.3.1'
    compile 'org.apache.thrift:libthrift:0.9.1'
    compile 'joda-time:joda-time:2.3'
    compile 'org.joda:joda-convert:1.5'
    compile 'com.sclasen:akka-kafka_2.10:0.0.10'
    compile 'com.typesafe.akka:akka-slf4j_2.10:2.3.1'
    compile 'com.typesafe.akka:akka-testkit_2.10:2.3.1'
    compile 'io.confluent:kafka-avro-serializer:1.0'
    testCompile 'org.scalatest:scalatest_2.10:2.0'
    testCompile 'org.specs2:specs2_2.10:2.2.2'

    deployerJars "org.apache.maven.wagon:wagon-http:2.2"
}
