buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath group: 'com.diluv.schoomp', name: 'Schoomp', version: '1.2.6'
    }
}

plugins {
    id 'java'
    id "org.jetbrains.kotlin.jvm"
    id 'idea'
    // This needs to be in the root
    // https://github.com/FabricMC/fabric-loom/issues/612#issuecomment-1198444120
    // Also it looks like property lookups don't work this early
    id 'fabric-loom' version '1.6-SNAPSHOT' apply false

    id("at.petra-k.PKPlugin") version "0.1.0-pre-87"
    id("at.petra-k.PKSubprojPlugin") version "0.1.0-pre-87" apply false
}

repositories {
    mavenCentral()
}

pkpcpbp {
    modInfo {
        modID(project.modID)
        mcVersion(project.minecraftVersion)
        modVersion(project.modVersion)
    }
    curseforgeInfo {
        id 569849
        stability "beta"
        token(System.getenv("CURSEFORGE_TOKEN"))
    }
    modrinthInfo {
        id "nTW3yKrm"
        stability "beta"
        token(System.getenv("MODRINTH_TOKEN"))
    }
}

subprojects {
    apply plugin: 'java'
    apply plugin: 'kotlin'
    apply plugin: 'maven-publish'

    tasks.withType(JavaCompile).configureEach {
        it.options.encoding = 'UTF-8'
        it.options.release = 17
    }

    // Disables Gradle's custom module metadata from being published to maven. The
    // metadata includes mapped dependencies which are not reasonably consumable by
    // other mod developers.
    tasks.withType(GenerateModuleMetadata) {
        enabled = false
    }

    sourceSets.main.kotlin.srcDirs += 'src/main/java'

    java.toolchain.languageVersion = JavaLanguageVersion.of(17)
    java.withSourcesJar()
    java.withJavadocJar()

    processResources {
        exclude '.cache'
    }
    sourcesJar {
        duplicatesStrategy 'exclude'
    }
}

allprojects {
    gradle.projectsEvaluated {
        tasks.withType(JavaCompile) {
            options.compilerArgs << "-Xmaxerrs" << "1000"
        }
    }

    // disable most javadoc warnings
    javadoc.options.addStringOption('Xdoclint:none', '-quiet')
}

compileKotlin {
    kotlinOptions {
        jvmTarget = "17"
    }
}
compileTestKotlin {
    kotlinOptions {
        jvmTarget = "17"
    }
}

tasks.register("runAllDatagen") {
    dependsOn ":Forge:runXplatDatagen"
    dependsOn ":Forge:runForgeDatagen"
    dependsOn ":Fabric:runDatagen"
}
