apply from: rootDir.toString() + '/config.gradle'
apply from: rootDir.toString() + '/dependencies.gradle'
apply plugin: 'maven-publish'
apply plugin: 'signing'

def RELEASE_REPOSITORY_URL = (new File(layout.projectDirectory.asFile.parent, "aafRepo")).absolutePath
def SNAPSHOT_REPOSITORY_URL = (new File(layout.projectDirectory.asFile.parent, "aafRepo")).absolutePath

def isRelease = true

def sonatypeRepositoryUrl
def sonatypeRepositoryVersion
def sonatypeUserName
def sonatypePassword
def moduleName = project.name

if (isRelease) {
    println 'RELEASE BUILD'
    sonatypeRepositoryUrl = RELEASE_REPOSITORY_URL
    sonatypeRepositoryVersion = ""
} else {
    println 'DEBUG BUILD'
    sonatypeRepositoryUrl = SNAPSHOT_REPOSITORY_URL
    sonatypeRepositoryVersion = "-SNAPSHOT"
}

afterEvaluate {

    publishing {

        //发布的 jar 包配置
        publications {

            maven(MavenPublication) {
                groupId = rootProject.zixieGroupId
                artifactId = rootProject.zixieModuleInfo[moduleName].get("artifactId")
                version = rootProject.zixieModuleInfo[moduleName].get("version") + sonatypeRepositoryVersion
                if (moduleName == "RouterCompiler") {
                    from components.java
                    artifact sourcesJar
                    artifact javadocJar
                } else {
                    from components.release
                }

                signing {
                    sign publishing.publications
                }

                pom {

                    name = moduleName
                    description = "Android APP Factory"
                    url = "https://android.bihe0832.com/doc/"
                    properties = [
                            myProp          : "email",
                            "prop.with.dots": "code@bihe0832.com"
                    ]
                    licenses {
                        license {
                            name = 'The Apache License, Version 2.0'
                            url = 'https://www.apache.org/licenses/LICENSE-2.0.txt'
                        }
                    }
                    developers {
                        developer {
                            id = "bihe0832"
                            name = "zixie"
                            email = "code@bihe0832.com"
                        }
                    }
                    scm {
                        connection = "scm:git@github.com:bihe0832/AndroidAppFactory.git"
                        developerConnection = "scm:git@github.com:bihe0832/AndroidAppFactory.git"
                        url = "https://github.com/bihe0832/AndroidAppFactory"
                    }
                }

            }

        }
        //仓库地址配置
        repositories {
            maven {
                name = moduleName
                allowInsecureProtocol true
                url sonatypeRepositoryUrl
            }
        }
    }
}

