apply plugin: 'maven'

def mavenRepositoryUrl

if (isReleaseBuild()) {
    println 'RELEASE BUILD'
    mavenRepositoryUrl = "http://nexus.yidianling.com/repository/AndroidReleases/"
} else {
    println 'SNAPSHOTS BUILD'
    mavenRepositoryUrl = "http://nexus.yidianling.com/repository/AndroidSnapshots/"
}

def getRepositoryUsername() {
    return hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : "admin"
}

def getRepositoryPassword() {
    return hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : "fjoi#1+#@"
}

def isReleaseBuild() {
    return IS_PUBLISH.toBoolean();
}

afterEvaluate { project ->
    uploadArchives {
        repositories {
            mavenDeployer {
                pom.artifactId = project.getName().replace('_', "-")
                pom.groupId = "com.ydl"
                pom.version =  isReleaseBuild() ? VERSION_NAME : VERSION_NAME + "-SNAPSHOT"
                repository(url: mavenRepositoryUrl) {
                    authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
                }
            }
        }
    }

    uploadArchives.doFirst {
        // log
        println String.format(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n>>>>> [%s] 正在将[%s]版本的[%s]包上传到Maven的[%s]仓库 >>>>>\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
                , project.getName()
                , VERSION_NAME
                , "aar"
                , IS_PUBLISH.toBoolean() ? "release" : "snapshot"
        )
    }
}