plugins {
    java
    id("org.springframework.boot") version "3.4.4"
    id("io.spring.dependency-management") version "1.1.7"
}

group = "com.alttd.altitudeweb"
version = "0.0.1-SNAPSHOT"

java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(21)
    }
}

configurations {
    compileOnly {
        extendsFrom(configurations.annotationProcessor.get())
    }
}

repositories {
    mavenCentral()
}

dependencies {
    implementation(project(":open_api"))
    implementation(project(":database"))
    implementation(project(":frontend"))
    implementation(project(":discord"))
    annotationProcessor("org.projectlombok:lombok")
    implementation("com.mysql:mysql-connector-j:8.0.32")
    implementation("org.mybatis:mybatis:3.5.13")
    implementation("org.springframework.boot:spring-boot-starter-web")
    implementation("org.springframework.boot:spring-boot-configuration-processor")
    implementation("org.springframework.boot:spring-boot-starter-hateoas")
    implementation("org.springframework.boot:spring-boot-starter-security")
    implementation("org.springframework.security:spring-security-oauth2-resource-server")
    implementation("org.springframework.security:spring-security-oauth2-jose")
    implementation("org.springframework.boot:spring-boot-starter-mail:3.1.5")
    implementation("org.springframework.boot:spring-boot-starter-thymeleaf")

    //Open API
    implementation("io.swagger.core.v3:swagger-annotations:2.2.37")
    implementation("io.swagger.core.v3:swagger-models:2.2.37")

    //AOP
    implementation("org.aspectj:aspectjrt:1.9.19")
    implementation("org.aspectj:aspectjweaver:1.9.19")
    implementation("org.springframework:spring-aop")
    implementation("org.springframework:spring-aspects")

    testRuntimeOnly("org.junit.platform:junit-platform-launcher")
    testImplementation("org.springframework.boot:spring-boot-starter-test")
}

tasks.compileJava {
    dependsOn(":frontend:npmBuild")
}

tasks.withType<Test> {
    useJUnitPlatform()
}

tasks.bootJar {
    mainClass.set("com.alttd.altitudeweb.AltitudeWebApplication")
    archiveBaseName.set("altitudeweb")
    archiveClassifier.set("")
}

tasks.processResources {
    dependsOn("includeFrontend")
}

tasks.register<Copy>("includeFrontend") {
    description = "Copy the built frontend to the Spring Boot static resources directory"
    dependsOn(":frontend:npmBuild")
    from("${project.rootDir}/frontend/dist")
    into(layout.buildDirectory.dir("resources/main/static"))
    doNotTrackState("Cannot reliably track state in the static directory")
}
