plugins {
    id 'java'
    id 'maven-publish'
    id 'net.minecrell.licenser' version '0.4.1'
    id 'com.github.sherter.google-java-format' version '0.8'
}

apply plugin: 'java'
apply plugin: 'com.github.sherter.google-java-format'

googleJavaFormat {
    toolVersion '1.7'
}

repositories {
    maven {
        url "https://plugins.gradle.org/m2/"
    }
    maven {
        url "https://oss.sonatype.org/content/repositories/snapshots/"
    }
    mavenCentral()
}

dependencies {
    implementation group: 'org.springframework.boot', name: 'spring-boot', version: "${bootVersion}"
    implementation group: 'org.springframework.boot', name: 'spring-boot-autoconfigure', version: "${bootVersion}"
    implementation group: 'io.temporal', name: 'temporal-sdk', version: "${temporalVersion}"
    implementation(group: 'io.temporal', name: 'temporal-testing', version: "${temporalVersion}") {
        exclude module: 'slf4j-simple'
    }

    implementation 'org.springframework:spring-aspects:5.2.7.RELEASE'
    implementation group: 'net.bytebuddy', name: 'byte-buddy', version: '1.11.0'
    compileOnly 'org.projectlombok:lombok:1.18.12'
    annotationProcessor 'org.projectlombok:lombok:1.18.12'

    implementation group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: "${bootVersion}"
    testCompileOnly 'org.projectlombok:lombok:1.18.12'
    testAnnotationProcessor 'org.projectlombok:lombok:1.18.12'
}

group = 'com.github.applicaai'
version = '0.12.0-SNAPSHOT'
java {
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8
}

publishing {
    repositories {
        maven {
            name = "GitHubPackages"
                url = uri("https://oss.sonatype.org/content/repositories/snapshots")
                credentials {
                    username = project.findProperty("ossrhUser")
                    password = project.findProperty("ossrhPassword")
                }
         }
    }
    publications {
        maven(MavenPublication) {
            from(components.java)
        }
    }
}

compileJava {
    dependsOn 'googleJavaFormat'
}

tasks.withType(JavaCompile) {
    options.encoding = 'UTF-8'
}

task execute(type: JavaExec) {
    main = findProperty("mainClass") ?: ""
    classpath sourceSets.main.runtimeClasspath + sourceSets.test.runtimeClasspath
}

test {
    useJUnitPlatform()
    testLogging {
        events "passed", "skipped", "failed"
    }
}

license {
    header rootProject.file('license-header.txt')
    matching(includes:['**/ai/applica/spring/boot/starter/temporal/samples/**']) {
        header = file('license-header-temporal.txt')
    }
}
