//buildscript {
//    repositories {
//        //使用阿里的maven镜像
//        maven { url 'http://maven.aliyun.com/nexus/content/groups/public'}
//    }
//    dependencies {
//        //引入bintray插件
//        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
//    }
//}

Properties properties = new Properties()
properties.load(project.file('local.properties').newDataInputStream())
println properties;
task sourcesJar(type: Jar, dependsOn: classes) {
    classifier = 'sources'
    from sourceSets.main.allSource
}

task javadocJar(type: Jar, dependsOn: javadoc) {
    classifier = 'javadoc'
    from javadoc.destinationDir
}

//apply plugin: 'java-library'
//apply plugin: 'maven-publish'
//apply plugin: 'com.jfrog.bintray'

def pomConfig = {
    licenses {
        license {
            name LICENSE_NAME
            url LICENSE_URL
            distribution properties.getProperty("bintray.repo")
        }
    }
    developers {
        developer {
            id DEVELOPER_ID
            name DEVELOPER_NAME
            email DEVELOPER_EMAIL
        }
    }
    scm {
        //项目网站
        url PROJ_WEBSITEURL
    }
}

publishing {
    publications {
        MyPublication(MavenPublication) {
            from components.java
            artifact sourcesJar
            artifact javadocJar
            groupId PROJ_GROUP
            artifactId PROJ_NAME//com.example.projectName
            version PROJ_VERSION
            pom.withXml {
                def root = asNode()
                root.appendNode('description', PROJ_DESCRIPTION)
                root.appendNode('name', PROJ_NAME)
                root.appendNode('url', PROJ_WEBSITEURL)
                root.children().last() + pomConfig
            }
        }
    }
}


bintray {
    user =  properties.getProperty("bintray.user")//bintray的用户名，即显示在导航栏右侧的名字
    key = properties.getProperty("bintray.apikey")//Api key，见下文
    publications = ['MyPublication']//关联到上文maven publication的名字
    publish = true//如果false，还需要到网页上手动发布

    pkg {
        repo = properties.getProperty("bintray.repo")
        name = PROJ_NAME
        licenses = ['Apache-2.0']
        vcsUrl = PROJ_VCSURL
        labels = ['java', 'spring', 'async','dactor']

        version {
            gpg {
                sign = true //Determines whether to GPG sign the files. The default is false
                passphrase = properties.getProperty("bintray.gpg.password") //Optional. The passphrase for GPG signing'
            }
            name = PROJ_NAME
            desc = PROJ_DESCRIPTION
//            released = new Date()
            vcsTag = PROJ_VERSION
            mavenCentralSync {
                sync = true//是否同步到中央仓库
                user = properties.getProperty("bintray.oss.user")//见下文
                password = properties.getProperty("bintray.oss.password")//见下文
            }
        }
    }
}