Scripts/jfmod/src/main/kotlin/jfmod.gradle.kts

118 lines
3.7 KiB
Plaintext
Raw Normal View History

import io.gitlab.jfronny.scripts.*
2022-10-06 19:30:52 +02:00
plugins {
id("jf.autoversion")
id("jf.maven-publish")
id("lom")
}
2022-12-29 13:14:20 +01:00
val splitRegex = Regex(", ?")
fun String.splitByComma() = splitRegex.split(this).filter { it.isNotBlank() }
val devOnlyModules by extra(prop("dev_only_module", "").splitByComma())
val nonModSubprojects by extra(prop("non_mod_project", "").splitByComma())
2022-10-06 19:30:52 +02:00
val self = project
2022-10-07 17:10:31 +02:00
if (hasProperty("maven_group")) group = prop("maven_group")
2022-10-06 19:30:52 +02:00
allprojects {
if (name in nonModSubprojects) return@allprojects
group = self.group
version = self.version
apply(plugin = "jf.maven-publish")
apply(plugin = "lom")
base {
2022-12-14 19:55:53 +01:00
archivesName.set(prop("archives_base_name", archivesName.get()))
2022-10-06 19:30:52 +02:00
}
lom {
minecraftVersion.set(prop("minecraft_version"))
loaderVersion.set(prop("loader_version"))
if (hasProperty("yarn_mappings")) yarn(prop("yarn_mappings"))
else mojmap()
}
if (hasProperty("libjf_version")) {
dependencies {
clientAnnotationProcessor(annotationProcessor("io.gitlab.jfronny.libjf:libjf-config-compiler-plugin-v2:${prop("libjf_version")}")!!)
}
tasks.withType<JavaCompile> {
2022-12-14 19:55:53 +01:00
options.compilerArgs.add("-AmodId=" + base.archivesName.get())
}
}
2022-10-06 19:30:52 +02:00
afterEvaluate {
self.allprojects.forEach { sub ->
if (sub != this && sub.name !in nonModSubprojects) {
loom {
mods {
register(sub.name) {
2022-10-07 18:42:33 +02:00
sourceSet(sub.sourceSets.main.get())
sourceSet(sub.sourceSets.client.get())
2022-10-06 19:30:52 +02:00
}
2022-10-07 18:42:33 +02:00
if (!sourceSets.testmod.get().resources.isEmpty) {
2022-10-07 18:20:43 +02:00
register("${sub.name}-testmod") {
2022-10-07 18:42:33 +02:00
sourceSet(sub.sourceSets.testmod.get())
2022-10-07 18:20:43 +02:00
}
2022-10-06 19:30:52 +02:00
}
}
}
}
}
}
}
subprojects {
if (name in nonModSubprojects) return@subprojects
self.tasks.deployDebug.dependsOn(tasks.deployDebug)
self.tasks.deployRelease.dependsOn(tasks.deployRelease)
tasks.named("javadoc") { enabled = false }
2022-10-06 19:30:52 +02:00
2022-10-07 18:42:33 +02:00
if (name !in devOnlyModules && !sourceSets.testmod.get().resources.isEmpty) {
2022-10-07 18:20:43 +02:00
//TODO register testmods of subprojects as testmodInclude automatically
// val configuration = configurations.create("testmodJar").name
// val testmodJarTask = tasks.named<Jar>("testmodJar").get()
// artifacts.add(configuration, testmodJarTask.archiveFile.get().asFile) {
// type = "jar"
// builtBy(testmodJarTask)
// }
//
// self.dependencies {
// testmodInclude(project(mapOf("path" to path, "configuration" to configuration)))
// }
}
self.dependencies {
api(project(mapOf("path" to project.path, "configuration" to "shadow")))
2022-10-07 18:42:33 +02:00
clientImplementation(sourceSets.client.get().output)
testmodImplementation(sourceSets.testmod.get().output)
2022-10-06 19:30:52 +02:00
2022-10-07 18:20:43 +02:00
if (name !in devOnlyModules) include(project)
}
2022-10-06 19:30:52 +02:00
}
val moveArtifacts by tasks.registering(Copy::class) {
val suffix = if (flavour.isEmpty()) "" else "-$flavour"
val sources = mapOf("latest$suffix.jar" to tasks.remapJar, "latest$suffix-dev.jar" to tasks.shadowJar)
for (source in sources) {
from(source.value.map { it.archiveFile }) {
this.rename { source.key }
}
dependsOn(source.value)
}
into(buildDir.resolve("artifacts"))
}
tasks.deployDebug.dependsOn(moveArtifacts)
2022-10-06 19:30:52 +02:00
if (hasProperty("curseforge_id")) apply(plugin = "jfmod.curseforge")
2022-10-07 18:20:43 +02:00
if (hasProperty("modrinth_id")) apply(plugin = "jfmod.modrinth")