plugins {
    id "com.github.johnrengelman.shadow" version "7.1.2"
}

architectury {
    platformSetupLoomIde()
    fabric()
}

loom {
    accessWidenerPath = project(":common").loom.accessWidenerPath
}

configurations {
    common
    shadowCommon // Don't use shadow from the shadow plugin because we don't want IDEA to index this.
    compileClasspath.extendsFrom common
    runtimeClasspath.extendsFrom common
    developmentFabric.extendsFrom common
}

dependencies {
    modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}"
    modApi "net.fabricmc.fabric-api:fabric-api:${rootProject.fabric_api_version}"

    common(project(path: ":common", configuration: "namedElements")) { transitive false }
    shadowCommon(project(path: ":common", configuration: "transformProductionFabric")) { transitive false }

    modLocalRuntime "dev.emi:emi-fabric:${rootProject.emi_version}"
    modImplementation("curse.maven:selene-499980:5619072")
    modImplementation("maven.modrinth:modmenu:7.2.1")

    modCompileOnly("me.shedaniel.cloth:cloth-config-fabric:${project.cloth_version}") {
        exclude group: 'net.fabricmc.fabric-api'
    }
    modCompileOnly "com.terraformersmc:modmenu:4.0.6", {
        exclude module: "fabric-api"
    }

}

processResources {

    inputs.property "version", project.version
    inputs.property "mod_id", rootProject.mod_id

    filesMatching("fabric.mod.json") {
        expand "version": project.version, "mod_id": rootProject.mod_id, "moonlight_version": rootProject.moonlight_version
    }
}

shadowJar {
    exclude "architectury.common.json"

    configurations = [project.configurations.shadowCommon]
    archiveClassifier = "dev-shadow"
}

remapJar {
    injectAccessWidener = true
    input.set shadowJar.archiveFile
    dependsOn shadowJar
    archiveClassifier = "fabric"
}

jar {
    archiveClassifier = "dev"
}

sourcesJar {
    def commonSources = project(":common").sourcesJar
    dependsOn commonSources
    from commonSources.archiveFile.map { zipTree(it) }
}

components.java {
    withVariantsFromConfiguration(project.configurations.shadowRuntimeElements) {
        skip()
    }
}

publishing {
    publications {
        mavenFabric(MavenPublication) {
            artifactId = rootProject.mod_id + "-" + project.name
            from components.java
        }
    }

    // See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
    repositories {
        // Add repositories to publish to here.
        maven {
            url = "https://www.cursemaven.com"
            allowInsecureProtocol = true
        }
        maven {
            name = "TerraformersMC"
            url = "https://maven.terraformersmc.com/releases"
        }
        maven {
            url = "https://maven.shedaniel.me"
        }
        maven {
            name = "Modrinth"
            url = "https://api.modrinth.com/maven"
            content {
                includeGroup "maven.modrinth"
            }
        }
    }
}

repositories {
    maven { url "https://maven.shedaniel.me/" }
    maven { url "https://maven.terraformersmc.com/releases" }
    maven { url "https://api.modrinth.com/maven" }
}