import io.gitlab.jfronny.scripts.* import org.gradle.api.internal.project.ProjectStateInternal import org.gradle.api.tasks.compile.JavaCompile import org.gradle.kotlin.dsl.dependencies import org.gradle.kotlin.dsl.withType plugins { id("jf.maven-publish") id("lom") } val args = extensions.create("jfModule") val lomArgs get() = extensions.getByName("lom") val isRoot = project == rootProject val rootArgs get() = rootProject.extensions.getByName("jfMod") insertEarlyAfterEvaluate { args.check(project) if (!isRoot) versionS = rootProject.versionS if (!hasProperty("loom.platform")) { // Platform is set manually. User will need to configure lom themselves too lom { copyFrom(rootArgs) } } if (rootArgs.libJfVersion.isPresent) { dependencies { if (SemanticVersion.parse(rootArgs.libJfVersion.get()) > SemanticVersion.parse("3.14.2")) { modImplementation(platform("io.gitlab.jfronny.libjf:libjf-bom:${rootArgs.libJfVersion.get()}")) } clientAnnotationProcessor(annotationProcessor("io.gitlab.jfronny.libjf:libjf-config-compiler-plugin-v2:${rootArgs.libJfVersion.get()}")!!) } tasks.withType { options.compilerArgs.add("-AmodId=" + base.archivesName.get()) } } if (rootArgs.fabricApiVersion.isPresent) { dependencies { listOf<(Any) -> Dependency?>( this::modImplementation, this::modLocalRuntime, this::modApi, this::include ).forEach { function -> function(platform("net.fabricmc.fabric-api:fabric-api-bom:${rootArgs.fabricApiVersion.get()}")) } } } } fun Project.pAfterEvaluate(action: (Project) -> Unit) = if ((this.state as ProjectStateInternal).hasCompleted()) action(this) else afterEvaluate { action(this) } afterEvaluate { rootProject.allprojects.forEach { it.pAfterEvaluate { sub -> if (sub != this && rootArgs.isMod(sub)) { if (rootArgs.isFabric(sub) && lomArgs.isFabric) { loom { mods { register(sub.name) { sourceSet(sub.sourceSets.main.get()) sourceSet(sub.sourceSets.client.get()) } if (!sourceSets.testmod.get().resources.isEmpty) { register("${sub.name}-testmod") { sourceSet(sub.sourceSets.testmod.get()) } } } } } //TODO handle forge } } } val devOnly = args.devOnly.getOrElse(false) if (!isRoot && !devOnly && !sourceSets.testmod.get().resources.isEmpty) { //TODO register testmods of subprojects as testmodInclude automatically // val configuration = configurations.create("testmodJar").name // val testmodJarTask = tasks.named("testmodJar").get() // artifacts.add(configuration, testmodJarTask.archiveFile.get().asFile) { // type = "jar" // builtBy(testmodJarTask) // } // // self.dependencies { // testmodInclude(project(mapOf("path" to path, "configuration" to configuration))) // } } if (!isRoot) rootProject.dependencies { if (rootArgs.isFabric && lomArgs.isFabric) { api(project(path = project.path, configuration = "shadow")) clientImplementation(sourceSets.client.get().output) testmodImplementation(sourceSets.testmod.get().output) if (!devOnly) include(project) } //TODO handle forge } } if (!isRoot) { rootProject.tasks.deployDebug.dependsOn(tasks.deployDebug) rootProject.tasks.deployRelease.dependsOn(tasks.deployRelease) tasks.named("javadoc") { enabled = false } }