buildscript {
    repositories {
        mavenCentral()
        maven {
                url "https://plugins.gradle.org/m2/"
        }
    }
}

//Gradle Plugins
plugins {
    id "com.matthewprenger.cursegradle" version "1.4.0"
    id 'java'
    id 'idea'
    id "com.modrinth.minotaur" version "2.+"
    id 'com.github.johnrengelman.shadow' version '8.1.1+'
    id 'net.neoforged.gradle.userdev' version '7.0.109'

}
apply plugin: 'eclipse'
apply plugin: 'maven-publish'


//Build variables
version = "3.0.7"
group = "de.erdbeerbaerlp.dcintegration"
archivesBaseName = "dcintegration-neoforge"

java.toolchain.languageVersion = JavaLanguageVersion.of(21)

//Gradle Repositories
repositories {
    maven { url 'https://jitpack.io' }
    maven {
        name = 'sponge'
        url = 'https://repo.spongepowered.org/maven'
    }
    maven { url "https://repository.dev.gotan.io/repository/gotan.os/" }
    maven { url "https://repo.opencollab.dev/maven-snapshots" }
    maven { url "https://repo.opencollab.dev/maven-releases" }
    maven {
        name = 'sonatype-oss'
        url = 'https://oss.sonatype.org/content/repositories/snapshots/'
    }
    flatDir {
        dirs 'libs'
    }
    maven { url "https://repo.erdbeerbaerlp.de/repository/maven-public/" }
}

//ShadowJar
configurations {
    embed
    compileOnly.extendsFrom(embed)
}

sourceSets.main.resources { srcDir 'src/generated/resources' }
task release {

}

shadowJar {
    archiveClassifier = "${project.mcVersion}"
    configurations = [project.configurations.embed]
    relocate 'org.slf4j', 'dcshadow.org.slf4j'
}

artifacts {
    archives tasks.shadowJar
}
configurations.all {
    resolutionStrategy {
        cacheChangingModulesFor 1, 'minutes'
    }
}
//Dependencies
dependencies {
    // =========  Common  =====================
    embed('de.erdbeerbaerlp:dcintegration.common:3.0.7') {
        changing = true
        transitive = false
    }

    // =========  NeoForge =============
    implementation "net.neoforged:neoforge:20.6.48-beta"

    //Dynmap-API
    compileOnly('com.github.webbukkit:DynmapCoreAPI:2.5')
}

//Manifest attributes
jar {
    archiveClassifier = "${project.mcVersion}"
    manifest {
        attributes([
                'Maven-Artifact'          : "${project.group}:${project.archivesBaseName}:${project.version}",
                'Timestamp'               : System.currentTimeMillis(),
                "Specification-Title"     : "dcintegration",
                "Specification-Vendor"    : "dcintegration",
                "Specification-Version"   : "1", // We are version 1 of ourselves
                "Implementation-Title"    : project.name,
                "Implementation-Version"  : "${project.version}",
                "Implementation-Vendor"   : "dcintegration",
                "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"),
                'MixinConnector'          : 'de.erdbeerbaerlp.dcintegration.forge.DCMixinConnector'
        ])
    }
}

//Curseforge publishing
curseforge {
    if (project.hasProperty('curseforge.apikey')) { // $GRADLE_USER_HOME/gradle.properties
        apiKey = getProperty("curseforge.apikey")
        project {
            id = '324952'
            changelog = project.changelog
            releaseType = project.releaseType.toLowerCase()
            addGameVersion "${project.mcVersion}"
            mainArtifact(jar) {
                displayName = "DiscordIntegration-NeoForge $version (MC ${project.mcVersion})"
            }
            relations {
                optionalDependency("luckperms")
            }
        }
    }
}
modrinth {
    if (project.hasProperty('modrinth.apikey')) { // $GRADLE_USER_HOME/gradle.properties
        token = getProperty("modrinth.apikey")
        projectId = 'rbJ7eS5V'
        versionNumber = version + "-${project.mcVersion}"
        versionName = "DiscordIntegration-NeoForge $version (MC ${project.mcVersion})"
        uploadFile = shadowJar
        changelog = project.changelog
        gameVersions = ["${project.mcVersion}"]
        loaders = ['neoforge']
        versionType = project.releaseType.toUpperCase()
        dependencies {
            optional.project "luckperms"
        }
    }
}

tasks.release.dependsOn(tasks.build, tasks.curseforge, tasks.modrinth)
