plugins {
    id 'java-library'
    id 'halo.publish'
    id 'jacoco'
    id "io.freefair.lombok"
    id "com.github.ben-manes.versions"
}

group = 'run.halo.app'
description = 'API of halo project, connecting by other projects.'

java {
    sourceCompatibility = JavaVersion.VERSION_17
    targetCompatibility = JavaVersion.VERSION_17
}

compileJava.options.encoding = "UTF-8"
compileTestJava.options.encoding = "UTF-8"
javadoc.options.encoding = "UTF-8"

repositories {
    mavenCentral()
    maven { url 'https://repo.spring.io/milestone' }
    maven { url 'https://s01.oss.sonatype.org/content/repositories/snapshots' }
}

dependencies {
    api platform(project(':platform:application'))

    api 'org.springframework.boot:spring-boot-starter-actuator'
    api 'org.springframework.boot:spring-boot-starter-data-jpa'
    api 'org.springframework.boot:spring-boot-starter-mail'
    api 'org.springframework.boot:spring-boot-starter-thymeleaf'
    api 'org.springframework.boot:spring-boot-starter-webflux'
    api 'org.springframework.boot:spring-boot-starter-validation'
    api 'org.springframework.boot:spring-boot-starter-data-r2dbc'
    api 'org.springframework.session:spring-session-core'

    // Spring Security
    api 'org.springframework.boot:spring-boot-starter-security'
    api 'org.springframework.security:spring-security-oauth2-jose'
    api 'org.springframework.security:spring-security-oauth2-client'
    api 'org.springframework.security:spring-security-oauth2-resource-server'

    // Cache
    api "org.springframework.boot:spring-boot-starter-cache"
    api "com.github.ben-manes.caffeine:caffeine"

    api "org.springdoc:springdoc-openapi-starter-webflux-ui"
    api 'org.openapi4j:openapi-schema-validator'
    api "net.bytebuddy:byte-buddy"

    // Apache Lucene
    api "org.apache.lucene:lucene-core"
    api "org.apache.lucene:lucene-queryparser"
    api "org.apache.lucene:lucene-highlighter"
    api "org.apache.lucene:lucene-backward-codecs"
    api 'org.apache.lucene:lucene-analysis-common'

    api "org.apache.commons:commons-lang3"
    api "io.seruco.encoding:base62"
    api "org.pf4j:pf4j"
    api "com.google.guava:guava"
    api "org.jsoup:jsoup"
    api "io.github.java-diff-utils:java-diff-utils"
    api "org.springframework.integration:spring-integration-core"
    api "com.github.java-json-tools:json-patch"
    api "org.thymeleaf.extras:thymeleaf-extras-springsecurity6"
    api 'org.apache.tika:tika-core'
    api "org.imgscalr:imgscalr-lib"
    api 'com.drewnoakes:metadata-extractor'

    api "io.github.resilience4j:resilience4j-spring-boot3"
    api "io.github.resilience4j:resilience4j-reactor"

    api "com.j256.two-factor-auth:two-factor-auth"

    runtimeOnly 'io.r2dbc:r2dbc-h2'
    runtimeOnly 'org.postgresql:postgresql'
    runtimeOnly 'org.postgresql:r2dbc-postgresql'
    runtimeOnly 'org.mariadb:r2dbc-mariadb'
    runtimeOnly 'io.asyncer:r2dbc-mysql'

    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testImplementation 'org.springframework.security:spring-security-test'
    testImplementation 'io.projectreactor:reactor-test'
}

java {
    withSourcesJar()
    withJavadocJar()
}

publishing {
    publications.named('mavenJava', MavenPublication) {
        from components.java
        pom {
            name = 'API library'
            description = "$project.description"
        }
    }
}

tasks.named('test') {
    useJUnitPlatform()
    finalizedBy jacocoTestReport
}

tasks.named('jacocoTestReport') {
    reports {
        xml.required = true
        html.required = false
    }
}
