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

Properties properties = new Properties()
properties.load(project.rootProject.file('scripts/maven.properties').newDataInputStream())
properties.load(new FileInputStream("${projectDir}/pom.properties"))

if (new File("local.properties").exists()) {
    properties.load(project.rootProject.file('local.properties').newDataInputStream())
}

def user = System.getenv("BINTARY_USER")
def apiKey = System.getenv("BINTARY_APIKEY")
def repo = System.getenv("BINTARY_REPO")

if (user == null || user.length() == 0) {
    user = properties.user
}
if (apiKey == null || apiKey.length() == 0) {
    apiKey = properties.apiKey
}
if (repo == null || repo.length() == 0) {
    repo = properties.releasesRepository
}

afterEvaluate {
    signing {
        sign(publishing.publications)
    }
    publishing {
        publications {
            release(MavenPublication) {
                groupId = properties.groupId
                artifactId = properties.artifactId
                version = rootProject.ext.Version
                pom {
                    name = 'Doric'
                    description = 'A cross-platform development framework for Android & iOS & Web & Qt'
                    url = 'https://github.com/doric-pub/Doric'
                    licenses {
                        license {
                            name = 'The Apache License, Version 2.0'
                            url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                        }
                    }
                    developers {
                        developer {
                            id = 'osborn'
                            name = 'Pengfei Zhou'
                            email = 'pengfeizhou@foxmail.com'
                        }
                    }
                    scm {
                        connection = 'scm:git:git@github.com:doric-pub/Doric.git'
                        url = 'https://github.com/doric-pub/Doric'
                    }
                }
                afterEvaluate {
                    from components.release
                }
            }
        }
        repositories {
            maven {
                url = layout.buildDirectory.dir('staging-deploy')
//                name = 'ossrh-staging-api'
//                url = "https://ossrh-staging-api.central.sonatype.com/service/local/staging/deploy/maven2/"
//                credentials {
//                    username user
//                    password apiKey
//                }
            }
        }
    }
}