plugins {
    id 'io.franzbecker.gradle-lombok' version '4.0.0' apply false
}

import io.franzbecker.gradle.lombok.task.DelombokTask

subprojects {
    apply plugin: 'java'
    apply plugin: 'maven'
    apply plugin: 'io.franzbecker.gradle-lombok'

    group 'co.aikar'
    version '1.0.0-SNAPSHOT'

    sourceCompatibility = '1.8'
    targetCompatibility = '1.8'

    lombok {
        version = '1.18.12'
        sha256 = ''
    }

    repositories {
        mavenLocal()
        mavenCentral()
        jcenter()
        maven {
            name 'aikar'
            url 'https://repo.aikar.co/content/groups/aikar/'
        }
    }

    dependencies {
        compileOnly group: 'org.jetbrains', name: 'annotations', version: '15.0'
    }

    project.conf2ScopeMappings.addMapping(300, configurations.compileOnly, 'provided')

    // Delombok Task
    task delombok(type: DelombokTask, dependsOn: compileJava) {
        ext.outputDir = file("$buildDir/delombok")
        classpath += project.configurations.compileOnly
        outputs.dir(outputDir)
        sourceSets.main.java.srcDirs.each {
            inputs.dir(it)
            args(it, "-d", outputDir)
        }
    }

    task sourcesJar(type: Jar, dependsOn: classes) {
        dependsOn delombok
        classifier = 'sources'

        from sourceSets.main.allSource
    }

    javadoc {
        dependsOn delombok

        source = file("${buildDir}/${delombok.name}")
        failOnError = false
    }

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

    artifacts {
        archives javadocJar
        archives sourcesJar
    }

    task deploy() {
        dependsOn install
        dependsOn uploadArchives
    }

    if(project.hasProperty('aikarRepoUser') && project.hasProperty('aikarRepoPass')) {
        uploadArchives {
            repositories {
                mavenDeployer {
                    repository(url: 'https://repo.aikar.co/content/repositories/aikar-snapshots/') {
                        authentication(userName: aikarRepoUser, password: aikarRepoPass)
                    }

                    snapshotRepository(url: 'https://repo.aikar.co/content/repositories/aikar-snapshots/') {
                        authentication(userName: aikarRepoUser, password: aikarRepoPass)
                    }
                }
            }
        }
    }
}
