apply plugin: 'com.android.library'
apply plugin: 'maven'
apply plugin: 'signing'

android {
    buildToolsVersion "23.0.2"
    compileSdkVersion 23
}

android.libraryVariants.all { variant ->
  def name = variant.buildType.name
  if (name.equals(com.android.builder.core.BuilderConstants.DEBUG)) {
    return; // Skip debug builds.
  }
  task("javadoc${variant.name.capitalize()}", type: Javadoc) {
    description "Generates Javadoc for $variant.name."
    source = variant.javaCompile.source
    ext.androidJar = System.getenv("ANDROID_HOME") + "/platforms/${android.compileSdkVersion}/android.jar"
    classpath = files(variant.javaCompile.classpath.files) + files(ext.androidJar)
  }

  task("bundleJavadoc${variant.name.capitalize()}", type: Jar) {
    description "Bundles Javadoc into zip for $variant.name."
    classifier = "javadoc"
    from tasks["javadoc${variant.name.capitalize()}"]
  }
}

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

task jar(type: Jar) {
  from 'build/intermediates/classes/release'
}

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

artifacts {
  archives sourcesJar
  archives javadocJar
  archives jar
}

signing {
    sign configurations.archives
}

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

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

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

      pom.project {
        name 'KenBurnsView'
		artifactId 'kenburnsview'
        packaging 'jar', 'aar'
        description 'Android library that provides an extension to ImageView that creates an immersive experience by animating its drawable using the Ken Burns Effect.'
        url 'https://github.com/flavioarfaria/KenBurnsView'

        scm {
          connection 'scm:git@github.com:flavioarfaria/KenBurnsView.git'
          developerConnection 'scm:git@github.com:flavioarfaria/KenBurnsView.git'
          url 'scm:git@github.com:flavioarfaria/KenBurnsView.git'
        }

        licenses {
          license {
            name 'The Apache License, Version 2.0'
            url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
          }
        }

        developers {
          developer {
            id 'flavioarfaria'
            name 'Flavio Faria'
          }
        }
      }
    }
  }
}
