apply plugin: 'com.android.library'
apply plugin: 'groovyx.android'

android {
  compileSdkVersion project.compileSdkVersion
  buildToolsVersion project.buildToolsVersion

  defaultConfig {
    minSdkVersion project.minSdkVersion
    targetSdkVersion project.compileSdkVersion
    versionCode 1
    versionName project.version

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

  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_6
    targetCompatibility JavaVersion.VERSION_1_6
  }

  lintOptions {
    abortOnError true
    disable 'InvalidPackage'
  }

  packagingOptions {
    exclude 'META-INF/LICENSE'
  }

  dexOptions {
    preDexLibraries false
    javaMaxHeapSize "1G"
  }
}

dependencies {
  compile "org.codehaus.groovy:groovy:$groovyVersion:grooid"

  compile "com.android.support:support-annotations:$supportLibVersion"
  compile 'com.android.support.test:runner:0.5'

  compile 'com.linkedin.dexmaker:dexmaker-mockito:2.2.0'

  compile("org.spockframework:spock-core:$spockVersion") {
    exclude group: 'org.codehaus.groovy'
    exclude group: 'junit'
  }
}

configurations.all {
  // force anything that depends on support-annotations to always use the latest version
  resolutionStrategy.force "com.android.support:support-annotations:$supportLibVersion"
  resolutionStrategy.force 'junit:junit:4.12'
}

apply from: "$rootDir/gradle/compile.gradle"
apply from: "$rootDir/gradle/publishing.gradle"
apply from: "$rootDir/gradle/bintray.gradle"
apply from: "$rootDir/gradle/artifactory.gradle"

task publishJavadoc(type: Exec) {
  dependsOn 'androidJavadocs'
  commandLine 'bash', '-c',
"""
#!/bin/bash

set -ex

REPO="git@github.com:pieces029/android-spock.git"
DIR=temp-clone

# Delete any existing temporary website clone
rm -rf \$DIR

# Clone the current repo into temp folder
git clone \$REPO \$DIR

# Move working directory into temp folder
cd \$DIR

# Checkout and track the gh-pages branch
git checkout -t origin/gh-pages

# Delete everything
rm -rf *

# Copy everything from javadocs folder
cp -r $buildDir/docs/javadoc/* .

# Stage all files in git and create a commit
git add .
git add -u
git commit -m "Website at \$(date)"

# Push the new files up to GitHub
git push origin gh-pages

# Delete our temp folder
cd ..
rm -rf \$DIR
"""
}

task release {
  description = 'Release a version and publish the javadocs (must run with -Prelease)'
  dependsOn clean, assemble, check, bintrayUpload, publishJavadoc
}

// The default 'assemble' task only applies to normal variants. Add test variants as well.
android.testVariants.all { variant ->
  tasks.getByName('assemble').dependsOn variant.assemble
}
