plugins {
	id 'maven-publish'
	id 'fabric-loom' version "${loom_version}"
}

base {
	archivesName = archives_base_name
}

version = "${mod_version}-fabric-${minecraft_version}"
group = maven_group

repositories {
}

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

	modImplementation "net.fabricmc.fabric-api:fabric-api:${fabric_version}"
}

processResources {
	inputs.property "version", mod_version

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

tasks.withType(JavaCompile).configureEach {
	// 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
	// If Javadoc is generated, this must be specified in that task too.
	it.options.encoding = "UTF-8"

	// Minecraft 1.18 upwards uses Java 17.
	it.options.release = 21
}

java {
	sourceCompatibility = JavaVersion.VERSION_21
	targetCompatibility = JavaVersion.VERSION_21
	// 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 {
	from "LICENSE"
}

// configure the maven publication
publishing {
	publications {
		mavenJava(MavenPublication) {
			groupId = project.group
			artifactId = project.artifactId
			version = project.version
			// add all the jars that should be included when publishing to maven
			artifact(remapJar) {
				builtBy remapJar
			}
			artifact(sourcesJar) {
				builtBy remapSourcesJar
			}
		}
	}

	// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
	repositories {
        maven {
            name = "GitHubPackages"
            url = "https://maven.pkg.github.com/ate47/Xray"
            credentials {
                username = System.getenv("USERNAME")
                password = System.getenv("TOKEN")
            }
        }
	}
}
