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

version rootProject.williamchartVersion
group 'com.diogobernardino.williamchart'

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

publishing {
    publications {
        Production(MavenPublication) {
            artifact("$buildDir/outputs/aar/pointstooltip-release.aar")
            artifact sourcesJar
            groupId this.group
            artifactId 'tooltip-points'
            version this.version

            pom.withXml {
                def dependenciesNode = asNode().appendNode('dependencies')
                configurations.implementation.allDependencies.each {
                    if (it.name != 'unspecified') {
                        def dependencyNode = dependenciesNode.appendNode('dependency')
                        dependencyNode.appendNode('groupId', it.group)
                        dependencyNode.appendNode('artifactId', it.name)
                        dependencyNode.appendNode('version', it.version)
                    }
                }
            }
        }
    }
}

bintray {
    Properties properties = new Properties()
    File localPropertiesFiles = project.rootProject.file('local.properties')
    if (localPropertiesFiles.exists())
        properties.load(localPropertiesFiles.newDataInputStream())

    user = properties.containsKey('bintrayUser') ? properties.getProperty('bintrayUser') : System.getenv('BINTRAY_USER')
    key = properties.containsKey('bintrayApiKey') ? properties.getProperty('bintrayApiKey') : System.getenv('BINTRAY_API_KEY')
    publications = ['Production']
    configurations = ['archives']
    // Default: false. Whether to run this as dry-run, without deploying
    dryRun = false
    // Default: false. Whether to override version artifacts already published
    override = false
    // Default: false. Whether version should be auto published after an upload
    publish = true
    pkg {
        repo = 'maven' // the name of the repository you created on Bintray
        name = 'com.diogobernardino.williamchart:tooltip-points'
        // the name of the package you created inside it
        version {
            name = this.version
            released = new Date()
            vcsTag = this.version
        }
    }
}