plugins {
    id 'jacoco'
    id 'maven-publish'
    alias catalog.plugins.envelope apply false
    alias catalog.plugins.lombok apply false
}


allprojects {
    apply plugin: 'java-library'
    apply plugin: catalog.plugins.lombok.get().pluginId

    group = "net.woggioni"
    version = getProperty('wson.version')

    java {
        modularity.inferModulePath = true
        toolchain {
            languageVersion = JavaLanguageVersion.of(25)
            vendor = JvmVendorSpec.GRAAL_VM
        }
    }

    lombok {
        version = catalog.versions.lombok.get()
    }

    repositories {
        maven {
            url = getProperty('gitea.maven.url')
            content {
                includeGroup 'com.lys'
                includeGroup 'net.woggioni'
            }
        }
        mavenCentral()
    }

    pluginManager.withPlugin('jacoco') {
        test {
            finalizedBy jacocoTestReport
        }
        jacocoTestReport {
            dependsOn test
        }
    }

    dependencies {
        implementation catalog.xz
        compileOnly catalog.lombok

        testImplementation catalog.junit.jupiter.api
        testImplementation catalog.junit.jupiter.params
        testRuntimeOnly catalog.junit.jupiter.engine
        testRuntimeOnly catalog.junit.platform.launcher
    }

    test {
        useJUnitPlatform()
    }

    tasks.named(JavaPlugin.COMPILE_JAVA_TASK_NAME, JavaCompile) {
        options.release = 17
    }

    pluginManager.withPlugin(catalog.plugins.kotlin.jvm.get().pluginId) {
        compileKotlin {
            kotlinOptions.with {
                jvmTarget = '17'
            }
        }
    }

    pluginManager.withPlugin('maven-publish') {
        publishing {
            repositories {
                maven {
                    name = "Gitea"
                    url = uri(getProperty('gitea.maven.url'))

                    credentials(HttpHeaderCredentials) {
                        name = "Authorization"
                        value = "token ${System.getenv()["PUBLISHER_TOKEN"]}"
                    }

                    authentication {
                        header(HttpHeaderAuthentication)
                    }

                }
            }
        }
    }
}


dependencies {
    implementation catalog.jwo
    implementation catalog.slf4j.api

    testImplementation project('test-utils')
    testImplementation catalog.jackson.databind
}

java {
    withJavadocJar()
    withSourcesJar()
}

compileJava {
    options.compilerArgs << '-parameters'
}

ext {
    setProperty('jpms.module.name', 'net.woggioni.wson')
}

publishing {
    publications {
        maven(MavenPublication) {
            from(components["java"])
        }
    }
}
