plugins {
	id 'dev.architectury.loom'
	id 'maven-publish'
}

java {
	sourceCompatibility = JavaVersion.VERSION_21
	targetCompatibility = JavaVersion.VERSION_21
}

base {
	archivesName = project.archives_base_name
}

version = project.mod_version
group = project.maven_group

def mcVersion = "@MCVERSION@"
def forgeVersion = "@FORGEVERSION@"


loom {
	forge {
		mixinConfig "examplemod.mixins.json"
	}

	afterEvaluate {
		assert mixin.useLegacyMixinAp.get() == false
	}
}

repositories {
	// Add repositories to retrieve artifacts from in here.
	// You should only use this when depending on other mods because
	// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
	// See https://docs.gradle.org/current/userguide/declaring_repositories.html
	// for more information about repositories.
}

dependencies {
	// To change the versions see the gradle.properties file
	minecraft "com.mojang:minecraft:$mcVersion"
	if ("MAPPINGS".equals("loom.officialMojangMappings()")) {
		mappings loom.officialMojangMappings()
	} else {
		mappings loom.layered {
			it.mappings(MAPPINGS)
			it.mappings(PATCHES)
		}
	}

	forge "net.minecraftforge:forge:$forgeVersion"
}

tasks.withType(JavaCompile).configureEach {
	it.options.release = 21
}

java {
	// 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") {
		rename { "${it}_${project.archivesBaseName}"}
	}
}

// configure the maven publication
publishing {
	publications {
		mavenJava(MavenPublication) {
			// 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 {
		// Add repositories to publish to here.
		// Notice: This block does NOT have the same function as the block in the top level.
		// The repositories here will be used for publishing your artifact, not for
		// retrieving dependencies.
	}
}
processResources {
	doLast {
		java.nio.file.Path.of(outputs.files.asPath).resolve("META-INF/MANIFEST.MF").text = "Manifest-Version: 1.0\n" +
				"Automatic-Module-Name: ignoreme\n"
	}
}

configurations.all {
	resolutionStrategy.force("net.sf.jopt-simple:jopt-simple:5.0.4")
}