apply plugin: 'maven-publish'
apply plugin: 'com.jfrog.bintray'


// 定义参数
def gitUrl = 'https://github.com/0xm1nam0/RxCore.git'   // Git仓库的url
def groupIdDefined = "com.github.weiss"
def artifactIdDefined = "rxcore"
def versionDefined = "1.3.3"

// bintray平台信息配置
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
bintray {
    user = properties.getProperty("bintray.user") // local.properties里设置
    key = properties.getProperty("bintray.apikey") // local.properties里设置
    publications = ['Production']
//    configurations = ['archives']
    override = true
    pkg {
        repo = 'maven' // 必填。bintray平台仓库名，必须已经创建过。
        description = "RxJava2+Retrofit2 Core"
        name = "RxCore"  // 必填。仓库里包package的名称，没有的话会自动创建。
        licenses = ["Apache-2.0"] // 首次创建package则必须，否则选填。
        vcsUrl = gitUrl // 首次创建package则必须，否则选填。
        publish = true
        publicDownloadNumbers = true
//        dryRun = true
        version {
            name = "$versionDefined"
        }
    }
}

publishing {
    publications {
        Production(MavenPublication) {
            artifact("$buildDir/outputs/aar/core-release.aar")
            artifact sourcesJar
            artifact javadocJar
            groupId "$groupIdDefined"
            artifactId "$artifactIdDefined"
            version "$versionDefined"

            pom.withXml {
                def dependenciesNode = asNode().appendNode('dependencies')

                // Iterate over the implementation dependencies (we don't want the test ones), adding a <dependency> node for each
                configurations.implementation.allDependencies.each {
                    // Ensure dependencies such as fileTree are not included in the pom.
                    if (it.name != 'unspecified') {
                        def dependencyNode = dependenciesNode.appendNode('dependency')
                        dependencyNode.appendNode('groupId', it.group)
                        dependencyNode.appendNode('artifactId', it.name)
                        dependencyNode.appendNode('version', it.version)
                    }
                }
            }
        }
    }
}

// 生成sourceJar和javaDocJar构件
task sourcesJar(type: Jar) {
    from android.sourceSets.main.java.srcDirs
    classifier = 'sources'
}

task javadoc(type: Javadoc) {
    source = android.sourceSets.main.java.srcDirs
    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
    // destinationDir = file("../javadoc/")
    failOnError false
}

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

// 执行 ./gradlew clean bintrayUpload
