apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'com.jfrog.bintray'
apply plugin: 'com.github.dcendents.android-maven'

android {
  compileSdkVersion 28

  defaultConfig {
    minSdkVersion 16
    targetSdkVersion 28
  }

  sourceSets {
    main.java.srcDirs += 'src/main/kotlin'
  }
}

dependencies {
  api "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
  api 'com.android.support:support-annotations:28.0.0'
}

def GROUP = 'me.gujun.android'
def ARTIFACTID = 'span'
def VERSION = '1.7'

group = GROUP
version = VERSION

install {
  repositories.mavenInstaller {
    pom.project {
      name ARTIFACTID
      description 'Styling text with fun'
      url 'https://github.com/2dxgujun/Spannable-In-Kotlin'

      packaging 'aar'
      groupId GROUP
      artifactId ARTIFACTID

      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 '2dxgujun'
          name 'Jun Gu'
          email "2dxgujun@gmail.com"
        }
      }
    }
  }
}

try {
  Properties properties = new Properties()
  properties.load(project.rootProject.file('local.properties').newDataInputStream())

  bintray {
    user = properties.getProperty("bintrayUser")
    key = properties.getProperty("bintrayApiKey")
    configurations = ['archives']
    pkg {
      repo = 'maven'
      name = ARTIFACTID
      licenses = ['Apache-2.0']
      vcsUrl = 'https://github.com/2dxgujun/Spannable-In-Kotlin.git'
    }
  }

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

  task javadoc(type: Javadoc) {
    source = android.sourceSets.main.java.srcDirs
    classpath = files(project.android.getBootClasspath())
    excludes = ['**/*.kt']
  }

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

  artifacts {
    archives javadocJar
    archives sourcesJar
  }
} catch (Exception e) {
  println e
}