apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

apply plugin: 'maven'

dependencies {
    api 'org.openftc:easyopencv:1.5.3'
    implementation 'org.openftc:apriltag:1.1.1'
    implementation "androidx.core:core-ktx:1.6.0"
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
}

def groupId = 'com.arcrobotics.ftclib'
def artifactId = 'vision'
def version = '2.1.0'

def localReleaseDest = "${buildDir}/release/${version}"
def releaseStorageDir = "${projectDir}/ReleaseStorage"
def localReleaseCopyDest = "${releaseStorageDir}/current"
def pastReleaseStorageDest = "${releaseStorageDir}/releases"

task androidJavadocs(type: Javadoc) {
    failOnError = false
    source = android.sourceSets.main.java.srcDirs
    ext.androidJar = "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"
    classpath += files(ext.androidJar)
}

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

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

uploadArchives {
    repositories.mavenDeployer {
        pom.groupId = groupId
        pom.artifactId = artifactId
        pom.version = version
        // Add other pom properties here if you want (developer details / licenses)
        repository(url: "file://${localReleaseDest}")
    }
}

task zipRelease(type: Zip) {
    from localReleaseDest
    destinationDir buildDir
    archiveName "release-${version}.zip"
}

task generateRelease {
    doLast {
        copy {
            from "${buildDir}/release-${version}.zip"
            into(localReleaseCopyDest)
        }
        copy {
            from "${localReleaseCopyDest}/release-${version}.zip"
            into(pastReleaseStorageDest)
        }

        println "Release ${version} can be found at ${localReleaseDest}/"
        println "Release ${version} zipped can be found ${buildDir}/release-${version}.zip"
        println "Release ${version} has also been stored at ${localReleaseCopyDest}"
        println "Past releases can be found at ${pastReleaseStorageDest}"
    }
}

generateRelease.dependsOn(uploadArchives)
generateRelease.dependsOn(zipRelease)

artifacts {
    archives androidSourcesJar
    archives androidJavadocsJar
}


apply from: '../dependencies.gradle'
repositories {
    mavenCentral()
}
