allprojects {

    apply plugin: 'java'
    apply plugin: 'maven'
    apply plugin: 'com.novoda.bintray-release'

    group 'com.github.apigcc'
    version '1.7.1'

    sourceCompatibility = 1.8
    targetCompatibility = 1.8

    [compileJava, compileTestJava, javadoc]*.options*.encoding = 'UTF-8'

    repositories {
        maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' }
    }

    dependencies {
        compile 'ch.qos.logback:logback-classic:1.2.3'

        compileOnly 'org.projectlombok:lombok:1.18.12'
        annotationProcessor 'org.projectlombok:lombok:1.18.12'
        testCompileOnly 'org.projectlombok:lombok:1.18.12'
        testAnnotationProcessor 'org.projectlombok:lombok:1.18.12'
        testCompile 'junit:junit:4.13'
    }

    ext {
        DESCRIPTION = 'A rest document generator with parse the source code.'
        SITE_URL = 'https://github.com/apigcc/apigcc'
        GIT_URL = 'https://github.com/apigcc/apigcc.git'

        LICENSE = 'MIT License'

        DEVELOPER_ID = 'ayz6uem'
        DEVELOPER_NAME = 'ayz6uem'
        DEVELOPER_EMAIL = '360188606@qq.com'

        IS_UPLOADING = project.getGradle().startParameter.taskNames.any { it.contains('bintrayUpload') }
    }

    publish {
        userOrg = 'apigcc'
        groupId = group
        artifactId = name
        publishVersion = version
        desc = project.DESCRIPTION
        website = project.SITE_URL
//    bintrayUser = project.BINTRAYUSER
//    bintrayKey = project.BINTRAYKEY
        dryRun = false
    }
}

buildscript {
    repositories {
        maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' }
    }
    dependencies {
        classpath 'com.novoda:bintray-release:0.8.1'
    }
}


gradle.taskGraph.whenReady { taskGraph ->
    taskGraph.getAllTasks().find { it.path == ":generatePomFileForMavenPublication" }?.doLast {
        file("build/publications/maven/pom-default.xml").delete()
        println 'Overriding pom-file to make sure we can sync to maven!'
        pom {
            //noinspection GroovyAssignabilityCheck
            project {
                name "$project.name"
                artifactId name
                packaging 'jar'
                description DESCRIPTION
                url SITE_URL
                version version

                scm {
                    url GIT_URL
                    connection GIT_URL
                    developerConnection GIT_URL
                }

                licenses {
                    license {
                        name LICENSE
                    }
                }

                developers {
                    developer {
                        id DEVELOPER_ID
                        name DEVELOPER_NAME
                        email DEVELOPER_EMAIL
                    }
                }
            }
        }.writeTo("build/publications/maven/pom-default.xml")
    }
}