import org.gradle.api.artifacts.maven.MavenDeployment

buildscript {
    repositories {
        mavenCentral()
        maven { url 'http://jcenter.bintray.com' }
    }

    dependencies {
        classpath 'org.gradle.api.plugins:gradle-nexus-plugin:0.3'
        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.2'
    }
}

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

dependencies {
    compile gradleApi()
    compile localGroovy()
    compile 'com.android.tools.build:gradle:1.1.0'
    compile 'commons-io:commons-io:2.4'
    testCompile 'org.easytesting:fest-assert-core:2.0M10'
}

repositories {
    mavenCentral()
}

group = 'com.nabilhachicha'
version = '0.1.2'

modifyPom {
    project {
        name 'Android Native Dependencies'
        description 'Gradle plugin for resolving and downloading Android native dependencies (.so)'
        url 'https://github.com/nhachicha/android-native-dependencies'
        inceptionYear '2014'

        scm {
            url 'https://github.com/nhachicha/android-native-dependencies'
            connection 'scm:git:git://github.com/nhachicha/android-native-dependencies.git'
            developerConnection 'scm:git:ssh://git@github.com/nhachicha/android-native-dependencies.git'
        }

        licenses {
            license {
                name 'The Apache Software License, Version 2.0'
                url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                distribution 'repo'
            }
        }

        developers {
            developer {
                id 'nhachicha'
                name 'Nabil Hachicha'
                email 'nabil.hachicha@gmail.com'
            }
        }
    }
}

task srcJar(type: Jar) {
    classifier 'sources'
    from sourceSets.main.allSource
}

task gdocJar(type: Jar, dependsOn: groovydoc) {
    classifier 'groovydoc'
    from groovydoc.destinationDir
}

artifacts {
    archives srcJar
    archives gdocJar
    archives javadocJar
}

publishing {
    publications {
        mavenJava(MavenPublication) {
            from components.java

            artifact srcJar
            artifact gdocJar
            artifact javadocJar

            pom.withXml {
                def root = asNode()
                root.appendNode('name', 'Android Native Dependencies')
                root.appendNode('url', 'https://github.com/nhachicha/android-native-dependencies')
                root.appendNode('description', 'Gradle plugin for resolving and downloading Android native dependencies (.so)')
                root.appendNode('inceptionYear', '2014')

                def scm = root.appendNode('scm')
                scm.appendNode('url', 'https://github.com/nhachicha/android-native-dependencies')
                scm.appendNode('connection', 'scm:git:git://github.com/nhachicha/android-native-dependencies.git')
                scm.appendNode('developerConnection', 'scm:git:ssh://git@github.com/nhachicha/android-native-dependencies.git')

                def license = root.appendNode('licenses').appendNode('license')
                license.appendNode('name', 'The Apache Software License, Version 2.0')
                license.appendNode('url', 'http://www.apache.org/licenses/LICENSE-2.0.txt')
                license.appendNode('distribution', 'repo')

                def developers = root.appendNode('developers')
                def nabil = developers.appendNode('developer')
                nabil.appendNode('id', 'nhachicha')
                nabil.appendNode('name', 'Nabil Hachicha')
                nabil.appendNode('email', 'nabil.hachicha@gmail.com')
            }
        }
    }
}

bintray {
    key = project.hasProperty('bintray_apikey') ? project.getProperty('bintray_apikey') : null
    user = project.hasProperty('bintray_user') ? project.getProperty('bintray_user') : null
    publications = ['mavenJava']

    pkg {
        repo = 'gradle-plugins'
        name = 'android-native-dependencies'
        licenses = ['Apache-2.0']
    }
}

task wrapper(type: Wrapper) {
    gradleVersion = '2.2'
}
