// Project properties
version = "8.11"
group='com.appnexus.opensdk'

// Android build
apply plugin: 'com.android.library'

android {
    compileSdkVersion 32
    buildToolsVersion '32.0.0'

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

    sourceSets {
        main.manifest.srcFile 'AndroidManifest.xml'
        main.java.srcDir 'src'
        main.res.srcDir 'res'
        main.assets.srcDir 'assets'
        main.resources.srcDir 'src'
//        test.manifest.srcFile 'AndroidManifestTest.xml'
        test.java.srcDir 'test'
    }

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

dependencies {
    api fileTree(include: ['*.jar'], dir: 'libs')

    testImplementation 'androidx.test.ext:junit:1.1.5'
    testImplementation 'org.assertj:assertj-core:2.6.0'
    testImplementation 'org.robolectric:robolectric:4.3.1'
    testImplementation 'com.squareup.okhttp:mockwebserver:2.7.5'
    testImplementation 'androidx.annotation:annotation:1.3.0'
    testImplementation 'org.robolectric:shadows-httpclient:4.3.1'
    testImplementation 'org.mockito:mockito-core:2.24.0'
}

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

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

    pom_scm_connection = "scm:git:git@github.com:appnexus/mobile-sdk-android.git"
    pom_scm_developerConnection = "scm:git:git@github.com:appnexus/mobile-sdk-android.git"
    pom_scm_url = "git@github.com:appnexus/mobile-sdk-android.git"

    pom_license_name = "The Apache License, Version 2.0"
    pom_license_url = "http://www.apache.org/licenses/LICENSE-2.0.txt"

    pom_developer_name = "AppNexus Mobile Team"
    pom_developer_email = "sdk@appnexus.com"
    pom_developer_organization = "AppNexus, Inc."
    pom_developer_organizationUrl = "http://www.appnexus.com"

    pom_groupId = "com.appnexus.opensdk"
    pom_artifactId = "appnexus-sdk"
    pom_packaging = "aar"

    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(':sdk:bundleReleaseAar')
            groupId = project.pom_groupId
            artifactId = project.pom_artifactId
            version = project.version
            // the AAR file to include in the publication
            artifact("$buildDir/outputs/aar/sdk-release.aar")

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

                scm {
                    connection = project.pom_scm_connection
                    developerConnection = project.pom_scm_developerConnection
                    url = project.pom_scm_url
                }
                licenses {
                    license {
                        name = project.pom_license_name
                        url = project.pom_license_url
                    }
                }
                developers {
                    developer {
                        name = project.pom_developer_name
                        email = project.pom_developer_email
                        organizationUrl = project.pom_developer_organizationUrl
                    }
                }
            }
        }
    }
    repositories {
        maven {
            url = isReleaseBuild() ? project.pom_distribution_repo_url : project.pom_distribution_snapshotRepo_url

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