apply plugin: 'maven-publish'

/**
 * 从 local.properties 中提取 Maven 仓库账号信息
 */
//def localProperties = new Properties()
//localProperties.load(project.rootProject.file('local.properties').newDataInputStream())
//def mavenUserName = localProperties.getProperty("MavenUsername")
//def mavenPassword = localProperties.getProperty("MavenPassword")

/**
 * 上传的仓库地址
 */
def release_repository_url = "http://dailybuild2.yidian-inc.com:8088/repository/maven-releases/"
def snapshot_repository_url = "http://dailybuild2.yidian-inc.com:8088/repository/maven-snapshots/"

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

afterEvaluate {
    publishing {
        publications {
            Production(MavenPublication) {
                from components.release
                groupId rootProject.ext.group_id
                artifactId rootProject.ext.artifact_id
                version rootProject.ext.version_name
                // 上传source，这样使用放可以看到方法注释
                artifact generateSourcesJar
            }
        }
        repositories {
            // 定义 maven远程 仓库
            maven {
                // 可以有且仅有一个仓库不指定 name 属性，会隐式设置为 Maven
                name = version_name.endsWith('SNAPSHOT') ? "pbSnapshots" : "pbReleases"
                // 根据 versionName 来判断仓库地址
                url = version_name.endsWith('SNAPSHOT') ? snapshot_repository_url : release_repository_url
                // 仓库用户名密码
                credentials {
                    username = "android"
                    password = "Android2017"
                }
            }
            // 定义 mavenLocal 仓库
            mavenLocal {
                name = "pbMavenLocal"
                url = uri('../../repo')
            }
        }
    }
}