import org.gradle.internal.jvm.Jvm

plugins {
	kotlin("jvm") version "1.9.10"
	id("me.champeau.jmh") version "0.7.1"
	java
	application
}

group = "ru.dbotthepony.kstarbound"
version = "0.1-SNAPSHOT"

val lwjglVersion: String by project
val lwjglNatives: String by project
val kotlinVersion: String by project
val kotlinCoroutinesVersion: String by project
val nettyVersion: String by project
val caffeineVersion: String by project
val fastutilVersion: String by project
val gsonVersion: String by project
val log4jVersion: String by project
val guavaVersion: String by project
val junitVersion: String by project

repositories {
	maven {
		url = uri("https://maven.dbotthepony.ru/")
	}

	mavenCentral()
}

application {
	mainClass.set("ru.dbotthepony.kstarbound.MainKt")
}

java.toolchain.languageVersion.set(JavaLanguageVersion.of(17))

tasks.compileKotlin {
	kotlinOptions {
		jvmTarget = "17"
		freeCompilerArgs += "-opt-in=kotlin.RequiresOptIn"
		freeCompilerArgs += "-Xjvm-default=all"
	}
}

dependencies {
	val kommonsVersion: String by project

	implementation("org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion")
	implementation("org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion")
	implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlinCoroutinesVersion")

	implementation("org.apache.logging.log4j:log4j-api:$log4jVersion")
	implementation("org.apache.logging.log4j:log4j-core:$log4jVersion")

	testImplementation("org.junit.jupiter:junit-jupiter-api:$junitVersion")
	testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")

	implementation("com.google.code.gson:gson:$gsonVersion")

	implementation("it.unimi.dsi:fastutil:$fastutilVersion")

	implementation("com.google.guava:guava:$guavaVersion")

	implementation(platform("org.lwjgl:lwjgl-bom:$lwjglVersion"))

	implementation("org.lwjgl", "lwjgl")
	implementation("org.lwjgl", "lwjgl-glfw")
	implementation("org.lwjgl", "lwjgl-opengl")
	implementation("org.lwjgl", "lwjgl-opus")
	implementation("org.lwjgl", "lwjgl-stb")

	runtimeOnly("org.lwjgl", "lwjgl", classifier = lwjglNatives)
	runtimeOnly("org.lwjgl", "lwjgl-glfw", classifier = lwjglNatives)
	runtimeOnly("org.lwjgl", "lwjgl-opengl", classifier = lwjglNatives)
	runtimeOnly("org.lwjgl", "lwjgl-opus", classifier = lwjglNatives)
	runtimeOnly("org.lwjgl", "lwjgl-stb", classifier = lwjglNatives)

	val ffiVersion: String by project

	implementation("net.java.dev.jna:jna:5.13.0")
	implementation("com.github.jnr:jnr-ffi:$ffiVersion")

	implementation("ru.dbotthepony.kommons:kommons:[$kommonsVersion,)") { setTransitive(false) }
	implementation("ru.dbotthepony.kommons:kommons-gson:[$kommonsVersion,)") { setTransitive(false) }
	implementation("ru.dbotthepony.kommons:kommons-guava:[$kommonsVersion,)") { setTransitive(false) }

	implementation("com.github.ben-manes.caffeine:caffeine:$caffeineVersion")
	implementation(project(":luna"))

	implementation("io.netty:netty-transport:$nettyVersion")
}

jmh {
	iterations.set(5)
	timeOnIteration.set("1s")
	warmup.set("1s")
	fork.set(1)
	includes.add("ht")
	synchronizeIterations.set(false)
	threads.set(4)
}

tasks.getByName<Test>("test") {
	useJUnitPlatform()
}