// Project Properties
version = "1.44" // Instream SDK version

apply plugin: 'com.android.library'

android {
    compileSdkVersion 32
    buildToolsVersion '32.0.0'

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 32
        versionCode 43 // An integer value that represents the version of the code, relative to other versions. Increase for each release.
        versionName version
        consumerProguardFiles 'proguard-project.txt'
    }

    lintOptions {
        abortOnError false
    }
    testOptions {
        unitTests {
            includeAndroidResources = true
        }
    }

}

dependencies {
    api project(':sdk')
    testImplementation 'androidx.test.ext:junit:1.1.5'
    testImplementation 'org.assertj:assertj-core:1.7.0'
    testImplementation 'androidx.annotation:annotation:1.3.0'
    testImplementation 'com.squareup.okhttp:mockwebserver:2.5.0'
}

evaluationDependsOn(':sdk')
ext {
    pom_name = "AppNexus Android SDK: Instream Video"
    pom_description = "AppNexus's Android Advertising Libraries: Instream Video SDK"
    pom_url = "https://wiki.appnexus.com/display/sdk/Mobile+SDKs?src=search#MobileSDKs-Android"

    pom_groupId = "com.appnexus.opensdk"
    pom_artifactId = "appnexus-instreamvideo"
    pom_packaging = "aar"
    pom_version = project(':sdk').version + "-" + project.version

    pom_distribution_snapshotRepo_id = "ossrh"
    pom_distribution_snapshotRepo_url = "https://oss.sonatype.org/content/repositories/snapshots"
    pom_distribution_repo_id = "ossrh"
    pom_distribution_repo_url = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"

    username = project.hasProperty('nexusUsername') ? project.getProperties().get('nexusUsername') : "Replace your username here"
    password = project.hasProperty('nexusPassword') ? project.getProperties().get('nexusPassword') : "Replace your password here"
}


apply plugin: 'maven-publish'
apply plugin: 'signing'

def isReleaseBuild() {
    return version.contains("SNAPSHOT") == false
}

signing {
    required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") }
    sign publishing.publications
}

publishing {
    publications {
        mavenJava(MavenPublication) {
            signMavenJavaPublication.mustRunAfter(':instreamvideo:bundleReleaseAar')
            groupId = project.pom_groupId
            artifactId = project.pom_artifactId
            version = project.pom_version
            // the AAR file to include in the publication
            artifact("$buildDir/outputs/aar/instreamvideo-release.aar")

            pom.withXml {
                def dependenciesNode = asNode().appendNode('dependencies')
                configurations.api.allDependencies.each {
                    def dependencyNode = dependenciesNode.appendNode('dependency')
                    dependencyNode.appendNode('groupId', it.group)
                    dependencyNode.appendNode('artifactId', (it.name == "sdk" ? "appnexus-" : "") + it.name)
                    dependencyNode.appendNode('version', it.version)
                }
            }

            pom {
                name = project.pom_name
                packaging = project.pom_packaging
                description = project.pom_description
                url = project.pom_url

                scm {
                    connection = 'scm:git:git@github.com:appnexus/mobile-sdk-android.git'
                    developerConnection = 'scm:git:git@github.com:appnexus/mobile-sdk-android.git'
                    url = 'git@github.com:appnexus/mobile-sdk-android.git'
                }
                licenses {
                    license {
                        name = 'The Apache License, Version 2.0'
                        url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                    }
                }
                developers {
                    developer {
                        name = 'AppNexus Mobile Team'
                        email = 'sdk@appnexus.com'
                        organizationUrl = 'http://www.appnexus.com'
                    }
                }
            }
        }
    }
    repositories {
        maven {
            url = isReleaseBuild() ? project.pom_distribution_repo_url : project.pom_distribution_snapshotRepo_url

            credentials {
                username = project.username
                password = project.password
            }
        }
    }
}

repositories {
    maven {
        url "https://maven.google.com"
    }
    jcenter()
    mavenCentral()
}
