apply plugin: 'com.android.library'
apply plugin: 'maven-publish'
apply plugin: 'com.jfrog.bintray'

android {
  compileSdkVersion COMPILE_SDK_VERSION

  defaultConfig {
    minSdkVersion MIN_SDK_VERSION
    targetSdkVersion TARGET_SDK_VERSION

    versionCode VERSION_CODE
    versionName VERSION_NAME

    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    consumerProguardFiles 'proguard-rules.pro'
  }

  buildTypes {
    debug {
      minifyEnabled false
    }
    release {
      minifyEnabled false
    }
  }

  lintOptions {
    warning 'InvalidPackage'
  }

  compileOptions {
    targetCompatibility TARGET_COMPATIBILITY
    sourceCompatibility SOURCE_COMPATIBILITY
  }
}

dependencies {
  testImplementation lib.junit
  testImplementation lib.mockito_core

  androidTestImplementation lib.android_test_runner

  api lib.rxjava
  api lib.web3j
}

//region Publishing
task sourcesJar(type: Jar) {
  from android.sourceSets.main.java.srcDirs
  classifier "sources"
}

task javadoc(type: Javadoc) {
  source = android.sourceSets.main.java.srcDirs
  classpath += project.files(android.getBootClasspath().join(File.pathSeparator))

  failOnError = false
}

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

publishing {
  publications {
    MyPublication(MavenPublication) {
      groupId 'com.asfoundation'
      artifactId project.name
      version project.version
      artifact(sourcesJar)
      artifact(javadocJar)
      artifact("$buildDir/outputs/aar/${project.name}-release.aar")

      //The publication doesn't know about our dependencies, so we have to manually add them to the pom
      pom.withXml {
        def dependenciesNode = asNode().appendNode('dependencies')

        //Iterate over the api dependencies (we don't want the test ones), adding a <dependency> node for each
        configurations.api.allDependencies.each {
          def dependencyNode = dependenciesNode.appendNode('dependency')
          dependencyNode.appendNode('groupId', it.group)
          dependencyNode.appendNode('artifactId', it.name)
          dependencyNode.appendNode('version', it.version)
        }
      }
    }
  }
  repositories {
    maven {
      url "$buildDir/repo"
    }
  }
}

bintray {
  user = "${ASF_BINTRAY_USER}"
  key = "${ASF_BINTRAY_KEY}"
  publications = ['MyPublication']
  pkg {
    repo = 'asf'
    name = "${project.name}"
    licenses = ['GPL-3.0']
    vcsUrl = 'https://github.com/AppStoreFoundation/AppCoins-ethereumj'

    version {
      name = project.version
    }
  }
}
//endregion