plugins { java id("xyz.jpenilla.run-paper") version "3.0.1" } group = "org.adrianvictor" version = System.getenv("VERSION") ?: "unknown" val buildEnv = System.getenv("BUILD_CHANNEL") ?: if (System.getenv("JITPACK") != null) "jitpack" else "local" repositories { mavenCentral() maven("https://repo.papermc.io/repository/maven-public/") } /* ----------------------------------------- */ /* SUPPORTED VERSIONS */ /* ----------------------------------------- */ val mcVersions = listOf( "b1_7_3", "r1_21" ) /* ----------------------------------------- */ /* CREATE SOURCE SET PER VERSION */ /* ----------------------------------------- */ //tasks.withType { // inputs.property("version", project.version) // // filesMatching("plugin.yml") { // expand("version" to project.version) // } //} mcVersions.forEach { ver -> val ss = sourceSets.create(ver) { java.srcDir("src/$ver/java") resources.setSrcDirs( listOf( "src/$ver/resources", "src/main/resources" ) ) compileClasspath += sourceSets["main"].output runtimeClasspath += output + compileClasspath } if (ver == "r1_21") { configurations[ss.compileOnlyConfigurationName] .extendsFrom(configurations["compileOnly"]) } } /* ----------------------------------------- */ /* DEPENDENCIES */ /* ----------------------------------------- */ dependencies { add("compileOnly", "io.papermc.paper:paper-api:1.21.10-R0.1-SNAPSHOT") add("r1_21CompileOnly", "io.papermc.paper:paper-api:1.21.10-R0.1-SNAPSHOT") add("b1_7_3CompileOnly", files("libs/craftbukkit-1060.jar")) } /* ----------------------------------------- */ /* BUILD TASKS */ /* ----------------------------------------- */ mcVersions.forEach { ver -> tasks.register("jar${ver.replace(".", "_").replace("-", "_").replace("/", "_").replaceFirstChar { it.uppercase() }}") { duplicatesStrategy = DuplicatesStrategy.EXCLUDE from(sourceSets["main"].output) from(sourceSets[ver].output) archiveClassifier.set(ver) manifest { attributes( "TLib-Impl-Version" to ver, "TLib-Environment" to buildEnv ) } } } tasks.register("buildAll") { dependsOn(tasks.withType()) } // Task to merge service files val prepareServiceFiles = tasks.register("prepareServiceFiles") { val outputDir = layout.buildDirectory.dir("generated/service-files") val serviceFile = "META-INF/services/org.adrianvictor.lib.versioning.VersionedServiceRegistrar" // Define inputs val inputFiles = mcVersions.map { ver -> file("src/$ver/resources/$serviceFile") }.filter { it.exists() } inputs.files(inputFiles) outputs.dir(outputDir) doLast { val registrars = mutableSetOf() inputFiles.forEach { file -> println("Checking file: ${file.absolutePath}, exists: ${file.exists()}") if (file.exists()) { val lines = file.readLines().filter { it.isNotBlank() } println("Found lines: $lines") registrars.addAll(lines) } } val mergedFile = outputDir.get().file(serviceFile).asFile mergedFile.parentFile.mkdirs() mergedFile.writeText(registrars.joinToString("\n")) println("Merged service file content: \n${registrars.joinToString("\n")}") } } tasks.register("bundleAll") { from(sourceSets["main"].output) mcVersions.forEach { ver -> from(sourceSets[ver].output) { exclude("META-INF/services/org.adrianvictor.lib.versioning.VersionedServiceRegistrar") } } // Include the merged service file from(prepareServiceFiles) { into("META-INF/services") include("org.adrianvictor.lib.versioning.VersionedServiceRegistrar") } duplicatesStrategy = DuplicatesStrategy.EXCLUDE archiveClassifier.set("all-implementations") archiveVersion.set(project.version.toString()) manifest { attributes( "Implemented-Versions" to mcVersions.joinToString(",") ) } } tasks.withType().configureEach { duplicatesStrategy = DuplicatesStrategy.EXCLUDE } tasks.withType().configureEach { options.encoding = "UTF-8" } /* ----------------------------------------- */ /* JAVA SETTINGS */ /* ----------------------------------------- */ java { toolchain.languageVersion.set(JavaLanguageVersion.of(21)) } tasks.withType { options.encoding = "UTF-8" } /* ----------------------------------------- */ /* RUN SETTINGS */ /* ----------------------------------------- */ tasks.runServer { minecraftVersion("1.21.1") // Include ONLY the all-implementations jar as the plugin pluginJars.setFrom(tasks.named("bundleAll")) }