/*
 *  Copyright (C) 2017-present Albie Liang. All rights reserved.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  
 */

apply plugin: 'java'

apply plugin: 'application'
//apply plugin: 'maven'

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

group = "cc.suitalk.tools"            // Maven Group ID for the artifact，

// 这个version是library的版本，更新后也需要更改这个值
version = bintrayConfig.version
archivesBaseName = 'ipc-invoker-extension-annotation'

// For jar config
mainClassName = ''

jar {
    baseName = archivesBaseName
    version = this.version
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
}

sourceCompatibility = "1.7"
targetCompatibility = "1.7"

//uploadArchives {
//    repositories.mavenDeployer {
//        repository(url: "file:${System.getProperty("user.home")}/.debugMaven/repositories/release")
//    }
//}

//task packLibJar(type: Jar, dependsOn: classes) {
//    from files(sourceSets.main.output.classesDir)
//    baseName = archivesBaseName
//    version = this.version
//}

install {
    repositories.mavenInstaller {
        // This generates POM.xml with proper parameters
        pom {
            project {
                packaging 'jar'
                // Add your description here
                name 'A ag-extension for IPCInvoker to generate code.'
                url bintrayConfig.siteUrl
                // Set your license
                licenses {
                    license {
                        name bintrayConfig.licenseName
                        url bintrayConfig.licenseUrl
                    }
                }
                developers {
                    developer {
                        id bintrayConfig.developerId
                        name bintrayConfig.developerName
                        email bintrayConfig.developerEmail
                    }
                }
                scm {
                    connection bintrayConfig.gitUrl
                    developerConnection bintrayConfig.gitUrl
                    url bintrayConfig.siteUrl
                }
            }
        }
    }
}


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

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

artifacts {
    archives packJavadocJar
    archives packSourcesJar
}

Properties properties = new Properties()
File file = project.rootProject.file('bintray-config.properties');
if (file.isFile()) {
    properties.load(file.newDataInputStream())

    bintray {
        user = properties.getProperty("bintray.user")
        key = properties.getProperty("bintray.apikey")
        configurations = ['archives']
        pkg {
            repo = "maven"          //这个应该是传到maven的仓库的
            name = archivesBaseName    //发布的项目名字
            websiteUrl = bintrayConfig.siteUrl
            vcsUrl = bintrayConfig.gitUrl
            licenses = ["Apache-2.0"]
            publish = true
        }
    }
}