// Based on https://github.com/OnyxStudios/Cardinal-Components-API/blob/1.17/build.gradle
plugins {
    id "fabric-loom" version "0.12-SNAPSHOT" apply false
    id "com.matthewprenger.cursegradle" version "1.4.0"
    id "maven-publish"
    id "java-library"
}

group = "net.puzzlemc"
archivesBaseName = "puzzle"

subprojects {
    apply plugin: 'fabric-loom'
    apply plugin: 'com.matthewprenger.cursegradle'
    apply plugin: 'maven-publish'
    apply plugin: 'java-library'

    archivesBaseName = project.name
    group = "${rootProject.group}.${rootProject.archivesBaseName}"
}

allprojects {
    apply plugin: "fabric-loom"
    sourceCompatibility = targetCompatibility = JavaVersion.VERSION_17
    version = System.getenv("TRAVIS_TAG") ?: rootProject.mod_version

    configurations {
        dev
    }

    repositories {
        maven { url 'https://jitpack.io' }

    }

    dependencies {
        minecraft "com.mojang:minecraft:${rootProject.minecraft_version}"
        mappings "net.fabricmc:yarn:${rootProject.yarn_mappings}:v2"
        modApi "net.fabricmc:fabric-loader:${rootProject.loader_version}"
        modApi "net.fabricmc.fabric-api:fabric-api:${rootProject.fabric_version}"
    }

    processResources {
        inputs.property "version", project.version

        filesMatching("fabric.mod.json") {
            expand "version": project.version
        }
    }

    // ensure that the encoding is set to UTF-8, no matter what the system default is
    // this fixes some edge cases with special characters not displaying correctly
    // see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
    tasks.withType(JavaCompile).configureEach {
        it.options.encoding = "UTF-8"
        it.options.release = 17
    }

    java {
        // Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
        // if it is present.
        // If you remove this line, sources will not be generated.
        withSourcesJar()
    }

    jar {
    }

     afterEvaluate {
         artifacts {
             dev file: file("${project.buildDir}/libs/$archivesBaseName-${version}-dev.jar"), type: "jar", builtBy: sourcesJar
         }
     }
}

subprojects {
    version = rootProject.version
}

subprojects.each { remapJar.dependsOn("${it.path}:remapJar") }

repositories {
    maven {
        name = "JitPack"
        url = "https://jitpack.io"
    }
    maven {
        name = "TerraformersMC"
        url = "https://maven.terraformersmc.com/releases"
    }
    maven {
        name = 'AperLambda'
        url = 'https://aperlambda.github.io/maven'
    }
    mavenCentral()
    maven {
        name 'Gegy'
        url 'https://maven.gegy.dev'
    }
    maven {
        url = "https://api.modrinth.com/maven"
    }
    maven {
        url "https://www.cursemaven.com"
        content {
            includeGroup "curse.maven"
        }
    }
    maven {
        name = 'JitPack'
        url 'https://jitpack.io'
    }
    maven {
        url "https://maven.shedaniel.me/"
    }
}

dependencies {
    modImplementation ("net.fabricmc.fabric-api:fabric-api:${project.fabric_version}")
    modImplementation ("com.terraformersmc:modmenu:${project.mod_menu_version}") {
        exclude group: "net.fabricmc.fabric-api"
    }
    modImplementation ("maven.modrinth:cull-leaves:${project.cull_leaves_version}")
    modImplementation ("maven.modrinth:lambdynamiclights:${project.ldl_version}")
    modImplementation ("maven.modrinth:lambdabettergrass:${project.lbg_version}")
    modImplementation ("maven.modrinth:iris:${project.iris_version}")
    modCompileOnly ("maven.modrinth:cit-resewn:${project.cit_resewn_version}")
    modImplementation ("maven.modrinth:continuity:${project.continuity_version}")
    modImplementation ("maven.modrinth:animatica:${project.animatica_version}")
    modImplementation ("maven.modrinth:colormatic:${project.colormatic_version}")
    modImplementation ("maven.modrinth:borderless-mining:${project.borderless_mining_version}")
    modImplementation ("maven.modrinth:dynamic-fps:${project.dynamic_fps_version}")
    modImplementation("com.moandjiezana.toml:toml4j:${project.toml4j_version}")
    modImplementation ("maven.modrinth:entitytexturefeatures:${project.entitytexturefeatures_version}")
    modImplementation ("maven.modrinth:cem:${project.cem_version}")
    modImplementation "com.gitlab.Lortseam:completeconfig:${project.complete_config_version}"

    modImplementation("org.aperlambda:lambdajcommon:1.8.1") {
        exclude group: 'com.google.code.gson'
        exclude group: 'com.google.guava'
    }
    modImplementation "dev.lambdaurora:spruceui:${project.spruceui_version}"
    modImplementation "maven.modrinth:midnightlib:${project.midnightlib_version}"
    include "maven.modrinth:midnightlib:${project.midnightlib_version}"

    subprojects.each {
        api project(path: ":${it.name}", configuration: "dev")
        include project(":${it.name}")
    }
}

publishing {
    publications {
        mavenJava(MavenPublication) {
            artifact(file("${project.buildDir}/libs/${archivesBaseName}-${version}.jar")) {
                builtBy(remapJar)
            }
            pom.withXml {
                subprojects.each {
                    depNode.appendNode("groupId", it.group)
                    depNode.appendNode("artifactId", it.name)
                    depNode.appendNode("version", it.version)
                    depNode.appendNode("scope", "compile")
                }
            }
        }
    }
}
