def BINTRAY_ORG = System.env.BINTRAY_ORG ?: ""
def BINTRAY_USER = System.env.BINTRAY_USER ?: ""
def BINTRAY_API_KEY = System.env.BINTRAY_API_KEY ?: ""

apply plugin: "com.novoda.bintray-release"
apply from: rootProject.file("library_info.gradle")

task checkBintrayConfig {
  doLast {
    if (BINTRAY_ORG.isEmpty() ||
        BINTRAY_USER.isEmpty() ||
        BINTRAY_API_KEY.isEmpty()) {
      def cause = new Exception(
          "BINTRAY_ORG (\"$BINTRAY_ORG\"), BINTRAY_USER (\"$BINTRAY_USER\"), or " +
              "BINTRAY_API_KEY (\"$BINTRAY_API_KEY\") are not set in your environment variables.")
      throw new TaskExecutionException(it, cause)
    }
  }
}

afterEvaluate {
  bintrayUpload.dependsOn checkBintrayConfig
}
if (module_name == null || module_name.isEmpty()) {
  throw new Exception("module_must must be defined for each module.")
}

publish {
  bintrayUser = BINTRAY_USER
  bintrayKey = BINTRAY_API_KEY
  userOrg = BINTRAY_ORG
  groupId = library.publish_group
  artifactId = module_name
  publishVersion = library.publish_version
  desc = library.description
  website = library.website
  dryRun = false
}
