plugins {
    id 'com.gradle.plugin-publish' version '0.11.0'
    id 'net.researchgate.release' version '2.8.1'
    id 'pl.droidsonroids.jacoco.testkit' version '1.0.3' // required until https://github.com/gradle/gradle/issues/1465 is resolved
    id 'java-gradle-plugin'
    id 'groovy'
    id 'maven'
    id 'jacoco'
    id 'maven-publish'
}

group 'io.franzbecker'

sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
    jcenter()
}

dependencies {
    testCompile 'junit:junit:4.12'
    testCompile gradleTestKit()
    testCompile 'com.netflix.nebula:nebula-test:6.1.2'
}

task sourcesJar(type: Jar, dependsOn: classes) {
    classifier 'sources'
    from sourceSets.main.allSource
}

artifacts {
    archives sourcesJar
}

jacoco {
    toolVersion = "0.8.3"
}

jacocoTestReport {
    reports {
        xml.enabled = true
        html.enabled = true
    }
}

check.dependsOn jacocoTestReport

gradlePlugin {
    plugins {
        lombokPlugin {
            id = 'io.franzbecker.gradle-lombok'
            displayName = 'Gradle Lombok plugin'
            description = 'A gradle plugin that simplifies the usage of the Lombok annotation processor.'
            implementationClass = 'io.franzbecker.gradle.lombok.LombokPlugin'
        }
    }
}

pluginBundle {
    website = 'https://github.com/franzbecker/gradle-lombok'
    vcsUrl = 'https://github.com/franzbecker/gradle-lombok.git'
    tags = ['gradle', 'lombok']

    plugins {
        lombokPlugin {
            id = 'io.franzbecker.gradle-lombok'
        }
    }

    mavenCoordinates {
        groupId = 'io.franzbecker'
        artifactId = 'gradle-lombok'
    }
}

task updateReadmeVersion {
    doLast {
        def versionPattern = /\d+.\d+(.\d+)?/
        def encoding = 'UTF-8'
        File file = new File("../README.md")

        // String replacements - Readme isn't long enough to justify advanced code ;)
        String text = file.getText(encoding)
        text = text.replaceAll("gradle-lombok' version '${versionPattern}'", "gradle-lombok' version '${project.version}'")
        text = text.replaceAll("gradle-lombok/${versionPattern}", "gradle-lombok/${project.version}")

        file.setText(text, encoding)
    }
}
updateReadmeVersion.shouldRunAfter tasks.getByName('confirmReleaseVersion')

/*
 * Configure release plugin.
 * Remove tasks "updateVersion" and "commitNewVersion" as we don't want the new SNAPSHOT
 * version commit on the master branch.
 */
tasks.release.tasks -= ["updateVersion", "commitNewVersion"]
release {
    preTagCommitMessage = '[release] '
    tagCommitMessage = '[release] '
    tagTemplate = 'v${version}'
}
tasks.getByName('preTagCommit').dependsOn updateReadmeVersion

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