plugins {
    id 'java-library'
    id 'org.dmfs.gver' version '0.18.0'
    id 'io.github.gradle-nexus.publish-plugin' version '1.1.0' apply false
}

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

gver {
    issueTracker GitHub {
        repo = "dmfs/lib-recur"
        if (project.hasProperty("GITHUB_API_TOKEN")) {
            accessToken = GITHUB_API_TOKEN
        }
    }
    changes {
        are none when {
            affects only(matches(~/.*\.md/))
        }
        are major when {
            commitMessage contains(~/(?i)#(major|break(ing)?)\b/)
        }
        are minor when {
            commitMessage contains(~/(?i)#(?<issue>\d+)\b/) {
                where("issue") { isIssue { labeled "enhancement" } }
            }
        }
        are patch when {
            commitMessage contains(~/(?i)#(?<issue>\d+)\b/) {
                where("issue") { isIssue { labeled "bug" } }
            }
        }
        are minor when {
            commitMessage contains("#feature\\b")
        }
        otherwise patch
    }
    preReleases {
        on ~/main|master/ use { "beta" }
        on ~/(.*\/)?(?<name>.*)/ use { "alpha-${group('name')}.1" }
    }
    releaseBranchPattern ~/main|master$/
}

configurations {
    pom
}

apply from: 'publish.gradle'
apply from: 'jacoco.gradle'

allprojects {
    group 'org.dmfs'
    repositories {
        mavenCentral()
    }
}

if (project.hasProperty('SONATYPE_USERNAME') && project.hasProperty('SONATYPE_PASSWORD')) {
    apply plugin: 'io.github.gradle-nexus.publish-plugin'

    nexusPublishing {
        repositories {
            sonatype {
                username = SONATYPE_USERNAME
                password = SONATYPE_PASSWORD
            }
        }
    }
}

dependencies {
    compileOnly libs.srcless.annotations
    annotationProcessor libs.srcless.processors
    compileOnly 'org.eclipse.jdt:org.eclipse.jdt.annotation:2.2.600'
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.0'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.0'
    api 'org.dmfs:rfc5545-datetime:0.3'
    api libs.jems2
    testImplementation project("lib-recur-hamcrest")
    testImplementation project("lib-recur-confidence")
    testImplementation libs.jems2.testing
    testImplementation libs.jems2.confidence
    testImplementation libs.confidence.core
    testImplementation libs.confidence.engine
}


test {
    useJUnitPlatform()
}
