buildscript {
    repositories { mavenCentral() }
    dependencies {
        classpath libs.nebula.extra
    }
}
plugins {
    id 'pmd'
    id 'jacoco'
    alias libs.plugins.spotbugs
    id 'codenarc'
    id 'checkstyle'
    id 'maven-publish'
    id 'signing'
    id 'java-library'
    alias libs.plugins.nexus.publish
    alias libs.plugins.nebula.optional
    alias libs.plugins.coveralls
    alias libs.plugins.axion.release
}

scmVersion {
    tag { prefix = project.name + '-' }
    versionCreator 'versionWithBranch'
}
project.group = 'pl.allegro.tech.boot'
project.version = scmVersion.version

allprojects {
    repositories {
        mavenCentral()
    }
    apply plugin: 'groovy'
    sourceCompatibility = 17

    test {
        useJUnitPlatform()
    }
}
dependencies {
    api libs.spring.boot.starter.web
    api libs.handlebars.springmvc
    api libs.handlebars.guava.cache

    api libs.joda.time, optional
    api libs.handlebars.helpers, optional
    api libs.handlebars.jackson, optional
    api libs.spring.boot.configuration.processor, optional

    testImplementation libs.bundles.spock
    testImplementation libs.spring.boot.starter.test
}
compileJava.dependsOn(processResources)

checkstyle { toolVersion = '10.12.4' }

codenarc {
    toolVersion = '3.5.0'
    configFile = new File("${projectDir}/config/codenarc/test-rules.groovy")
}

codenarcTest {
    ignoreFailures true
    compilationClasspath = codenarcMain.compilationClasspath + sourceSets.test.compileClasspath + sourceSets.test.output
}

pmd {
    rulesMinimumPriority.set(2)
    ruleSets = [
            "category/java/bestpractices.xml",
            "category/java/codestyle.xml",
            "category/java/design.xml",
            "category/java/errorprone.xml",
            "category/java/performance.xml"
    ]
}

spotbugsTest {
    spotbugsTest.enabled = false
}

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

java {
    withSourcesJar()
    withJavadocJar()
}

publishing {
    publications {
        sonatype(MavenPublication) {
            from components.java

            pom {
                name = 'Spring Boot Starter Handlebars'
                description = 'Spring Boot auto-configuration for Handlebars template engine'
                url = 'https://github.com/allegro/handlebars-spring-boot-starter'
                inceptionYear = '2015'
                licenses {
                    license {
                        name = "The Apache License, Version 2.0"
                        url = "http://www.apache.org/licenses/LICENSE-2.0.txt"
                    }
                }
                developers {
                    developer {
                        id = "plesiecki"
                        name = "Paweł Lesiecki"
                    }
                }
                scm {
                    connection = "scm:svn:http://subversion.example.com/svn/project/trunk/"
                    developerConnection = "scm:git@github.com:allegro/handlebars-spring-boot-starter.git"
                    url = "https://github.com/allegro/handlebars-spring-boot-starter"
                }
            }
        }
    }
}

nexusPublishing {
    repositories {
        sonatype {
            username = System.getenv("SONATYPE_USERNAME")
            password = System.getenv("SONATYPE_PASSWORD")
        }
    }
}

if (System.getenv("GPG_KEY_ID")) {
    signing {
        useInMemoryPgpKeys(
                System.getenv("GPG_KEY_ID"),
                System.getenv("GPG_PRIVATE_KEY"),
                System.getenv("GPG_PRIVATE_KEY_PASSWORD")
        )
        sign publishing.publications
    }
}
