plugins {
    id 'java'
    id 'architectury-plugin'
    id 'maven-publish'
    id 'com.diffplug.spotless'
}

spotless {
    java {
        removeUnusedImports()
    }
}

architectury {
    compileOnly()
}

group = 'org.embeddedt'
// extract base version from tag, generate other metadata ourselves
def details = versionDetails()
def plusIndex = details.lastTag.indexOf("+")
if(plusIndex == -1) {
    plusIndex = details.lastTag.length()
}
def baseVersion = details.lastTag.substring(0, plusIndex)
def dirtyMarker = grgit.status().clean ? "" : ".dirty"
def commitHashMarker = details.commitDistance > 0 ? ("." + details.gitHash.substring(0, Math.min(4, details.gitHash.length()))) : ""
def preMarker = (details.commitDistance > 0 || !details.isCleanTag) ? ("-beta." + details.commitDistance) : ""
if(preMarker.length() > 0) {
    // bump to next patch release
    def versionParts = baseVersion.tokenize(".")
    baseVersion = "${versionParts[0]}.${versionParts[1]}.${versionParts[2].toInteger() + 1}"
}
def versionString = "${baseVersion}${preMarker}+mc${minecraft_version}${commitHashMarker}${dirtyMarker}"
version = versionString
archivesBaseName = rootProject.archives_base_name + '-' + project.name

sourceCompatibility = targetCompatibility = JavaVersion.VERSION_17

repositories {
    exclusiveContent {
        forRepository {
            maven {
                url "https://modmaven.dev"
            }
        }
        filter {
            includeGroup "appeng"
            includeGroup "vazkii.patchouli"
            includeGroup "mezz.jei"
        }
    }
    exclusiveContent {
        forRepository {
            maven {
                url "https://cursemaven.com"
            }
        }
        filter {
            includeGroup "curse.maven"
        }
    }
    exclusiveContent {
        forRepository {
            maven {
                name = 'ParchmentMC'
                url = 'https://maven.parchmentmc.org'
            }
        }
        filter {
            includeGroup "org.parchmentmc.data"
        }
    }
    exclusiveContent {
        forRepository {
            maven {
                url = 'https://maven.architectury.dev'
            }
        }
        filter {
            includeGroup "me.shedaniel"
        }
    }
    exclusiveContent {
        forRepository {
            maven {
                url = 'https://maven.latvian.dev/releases'
            }
        }
        filter {
            includeGroup "dev.latvian.mods"
        }
    }
    exclusiveContent {
        forRepository {
            maven {
                name = "Fuzs Mod Resources"
                url = "https://raw.githubusercontent.com/Fuzss/modresources/main/maven/"
            }
        }
        filter {
            includeGroup "fuzs"
        }
    }
    exclusiveContent {
        forRepository {
            maven {
                name = "Fabric maven"
                url = "https://maven.fabricmc.net/"
            }
        }
        filter {
            includeGroup "net.fabricmc"
        }
    }
    exclusiveContent {
        forRepository {
            maven {
                name = "Mod Menu"
                url = "https://maven.terraformersmc.com/releases/"
            }
        }
        filter {
            includeGroup "com.terraformersmc"
        }
    }
}
