buildscript {
	repositories {
		maven {
			name = "Fabric"
			url = "https://maven.fabricmc.net/"
			content {
				includeGroup "net.fabricmc"
				includeGroup "fabric-loom"
			}
		}
		mavenCentral()
	}
	dependencies {
		classpath "fabric-loom:fabric-loom.gradle.plugin:1.1.14"
	}
}

plugins {
	id "com.jfrog.artifactory" version "4.9.0"
}

apply plugin: "fabric-loom"
apply plugin: "maven-publish"

java.toolchain.languageVersion = JavaLanguageVersion.of(17)
java.withSourcesJar()
tasks.withType(JavaCompile) {
	options.encoding = "UTF-8"
	options.release = 17
}

if(rootProject.file("private.gradle").exists()) { //Publishing details
	apply from: "private.gradle"
}

archivesBaseName = "templates"
group = "io.github.cottonmc"
version = "2.0.2+1.20.1"

repositories {
	mavenCentral()
}

dependencies {
	minecraft "com.mojang:minecraft:1.20.1"
	mappings "net.fabricmc:yarn:1.20.1+build.2"
	modApi "net.fabricmc:fabric-loader:0.14.21"
	modApi "net.fabricmc.fabric-api:fabric-api:0.83.1+1.20.1"

	implementation "com.google.code.findbugs:jsr305:3.0.2"
}

loom {
	mixin {
		defaultRefmapName = "templates.refmap.json" //see templates.mixins.json. I just like to always specify the name
	}
}

processResources {
	inputs.property "version", project.version
	filesMatching("**/fabric.mod.json") {
		expand "version": project.version
	}
}

jar {
	from "LICENSE"
}

// configure the maven publication
// TODO: i'm far from a maven guru, this is probably broken & idk how to fix it -quat
publishing {
	publications {
		maven(MavenPublication) {
			// add all the jars that should be included when publishing to maven
			//artifact(jar) {
			//	builtBy remapJar
			//}
			artifact ("${project.buildDir.absolutePath}/libs/${archivesBaseName}-${project.version}.jar") { //release jar - file location not provided anywhere in loom
				classifier null
				builtBy remapJar
			}

			artifact ("${project.buildDir.absolutePath}/libs/${archivesBaseName}-${project.version}-dev.jar") { //release jar - file location not provided anywhere in loom
				classifier "dev"
				builtBy remapJar
			}

			artifact(sourcesJar) {
				builtBy remapSourcesJar
			}
		}
	}

	// select the repositories you want to publish to
	repositories {
		// uncomment to publish to the local maven
		// mavenLocal()
	}
}

artifactory {
	if (project.hasProperty("artifactoryUsername")) {
		contextUrl = "http://server.bbkr.space:8081/artifactory/"
		publish {
			repository {
				if (version.contains("SNAPSHOT")) {
					repoKey = "libs-snapshot"
				} else {
					repoKey = "libs-release"
				}

				username = artifactoryUsername
				password = artifactoryPassword
			}
			defaults {
				publications("maven")

				publishArtifacts = true
				publishPom = true
			}
		}
	} else {
		println "Cannot configure artifactory; please define ext.artifactoryUsername and ext.artifactoryPassword before running artifactoryPublish"
	}
}