apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'

install {
    repositories.mavenInstaller {
        pom.project {
            name 'WireGuard Tunnel Library'
            description 'Embeddable tunnel library for WireGuard for Android'
            url 'https://www.wireguard.com/'

            packaging 'aar'
            groupId groupName
            artifactId 'tunnel'
            version wireguardVersionName

            licenses {
                license {
                    name 'The Apache Software License, Version 2.0'
                    url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                    distribution 'repo'
                }
            }
            scm {
                connection 'scm:git:https://git.zx2c4.com/wireguard-android'
                url 'https://git.zx2c4.com/wireguard-android'
            }
            organization {
                name 'WireGuard'
                url 'https://www.wireguard.com/'
            }
        }
    }
}

bintray {
    user = hasProperty('BINTRAY_USER') ? getProperty('BINTRAY_USER') : System.getenv('BINTRAY_USER')
    key = hasProperty('BINTRAY_KEY') ? getProperty('BINTRAY_KEY') : System.getenv('BINTRAY_KEY')

    configurations = [ 'archives' ]

    pkg {
        repo = 'wireguard-android'
        name = 'wireguard-android'
        userOrg = 'wireguard'
        licenses = [ 'Apache-2.0' ]
        vcsUrl = 'https://git.zx2c4.com/wireguard-android'
        publish = true

        version {
            name = wireguardVersionName
        }
    }
}

android.libraryVariants.all { variant ->
    if (variant.name == 'release') {
        task javadoc(type: Javadoc) {
            source = variant.javaCompileProvider.get().source
            classpath = files((android.bootClasspath.join(File.pathSeparator)))
            classpath += variant.javaCompileProvider.get().classpath
            title = 'Embeddable WireGuard Tunnel for Android v$wireguardVersionName'
        }
        task javadocJar(type: Jar, dependsOn: javadoc) {
            archiveClassifier = 'javadoc'
            from javadoc.destinationDir
        }
        task sourcesJar(type: Jar) {
            archiveClassifier = 'sources'
            from android.sourceSets.main.java.srcDirs
        }
        artifacts {
            archives sourcesJar
            archives javadocJar
        }
    }
}
