plugins { id "java-library" id "eclipse" id "idea" id "maven-publish" id 'jacoco' id "fabric-loom" version "1.8.11" apply false id "com.diffplug.spotless" version "6.20.0" id "org.ajoberstar.grgit" version "5.2.2" id "me.modmuss50.remotesign" version "0.4.0" apply false id "me.modmuss50.mod-publish-plugin" version "0.4.5" } def ENV = System.getenv() version = project.version + "+" + (ENV.GITHUB_RUN_NUMBER ? "" : "local-") + getBranch() logger.lifecycle("Building Fabric: " + version) def metaProjects = [ 'deprecated', 'fabric-api-bom', 'fabric-api-catalog' ] def debugArgs = [ "-enableassertions", "-Dmixin.debug.verify=true", //"-Dmixin.debug.strict=true", "-Dmixin.debug.countInjections=true", ] import net.fabricmc.loom.util.gradle.SourceSetHelper import groovy.json.JsonSlurper import org.apache.commons.codec.digest.DigestUtils def getSubprojectVersion(project) { // Get the version from the gradle.properties file def version = project.properties["${project.name}-version"] if (!version) { throw new NullPointerException("Could not find version for " + project.name) } if (grgit == null) { return version + "+nogit" } def latestCommits = grgit.log(paths: [project.name], maxCommits: 1) if (latestCommits.isEmpty()) { return version + "+uncommited" } return version + "+" + latestCommits.get(0).id.substring(0, 8) + DigestUtils.sha256Hex(project.rootProject.minecraft_version).substring(0, 2) } def getBranch() { def ENV = System.getenv() if (ENV.GITHUB_REF) { def branch = ENV.GITHUB_REF return branch.substring(branch.lastIndexOf("/") + 1) } if (grgit == null) { return "unknown" } def branch = grgit.branch.current().name return branch.substring(branch.lastIndexOf("/") + 1) } def moduleDependencies(project, List depNames) { def deps = depNames.iterator().collect { project.dependencies.project(path: ":$it", configuration: 'namedElements') } def clientOutputs = depNames.iterator().collect { findProject(":$it").sourceSets.client.output } project.dependencies { deps.each { api it } clientOutputs.each { clientImplementation it } } // As we manually handle the maven artifacts, we need to also manually specify the deps. project.publishing { publications { mavenJava(MavenPublication) { pom.withXml { def depsNode = asNode().appendNode("dependencies") deps.each { def depNode = depsNode.appendNode("dependency") depNode.appendNode("groupId", it.group) depNode.appendNode("artifactId", it.name) depNode.appendNode("version", it.version) depNode.appendNode("scope", "compile") } } } } } } def testDependencies(project, List depNames) { def deps = depNames.iterator().collect { project.dependencies.project(path: ":$it", configuration: 'namedElements') } def clientOutputs = depNames.iterator().collect { findProject(":$it").sourceSets.client.output } project.dependencies { deps.each { testmodImplementation it } clientOutputs.each { testmodClientImplementation it } } } allprojects { group = "net.fabricmc.fabric-api" apply plugin: "maven-publish" apply plugin: "me.modmuss50.remotesign" tasks.withType(GenerateModuleMetadata) { enabled = false } remoteSign { requestUrl = ENV.SIGNING_SERVER pgpAuthKey = ENV.SIGNING_PGP_KEY jarAuthKey = ENV.SIGNING_JAR_KEY useDummyForTesting = ENV.SIGNING_SERVER == null afterEvaluate { // PGP sign all maven publications. sign publishing.publications.mavenJava } } publishing { setupRepositories(repositories) } if (metaProjects.contains(it.name)) { return } apply plugin: "java-library" apply plugin: "checkstyle" apply plugin: "fabric-loom" apply plugin: "com.diffplug.spotless" tasks.withType(JavaCompile).configureEach { it.options.release = 21 } java { // Must be added before the split source sets are setup. withSourcesJar() } loom { splitEnvironmentSourceSets() mixin { useLegacyMixinAp = true } } sourceSets { testmod { compileClasspath += main.compileClasspath runtimeClasspath += main.runtimeClasspath } testmodClient { compileClasspath += main.compileClasspath runtimeClasspath += main.runtimeClasspath compileClasspath += client.compileClasspath runtimeClasspath += client.runtimeClasspath compileClasspath += testmod.compileClasspath runtimeClasspath += testmod.runtimeClasspath } test { compileClasspath += testmodClient.compileClasspath runtimeClasspath += testmodClient.runtimeClasspath } } loom { runtimeOnlyLog4j = true runs { testmodClient { client() ideConfigGenerated project.rootProject == project name = "Testmod Client" source sourceSets.testmodClient } testmodServer { server() ideConfigGenerated project.rootProject == project name = "Testmod Server" source sourceSets.testmod } } } loom.runs.configureEach { vmArgs(debugArgs) } allprojects.each { p -> if (metaProjects.contains(project.name)) { return } loom.mods.register(p.name) { sourceSet p.sourceSets.main sourceSet p.sourceSets.client } loom.mods.register(p.name + "-testmod") { sourceSet p.sourceSets.testmod sourceSet p.sourceSets.testmodClient } } dependencies { minecraft "com.mojang:minecraft:$rootProject.minecraft_version" mappings "net.fabricmc:yarn:${rootProject.minecraft_version}${project.yarn_version}:v2" modApi "net.fabricmc:fabric-loader:${project.loader_version}" testmodImplementation sourceSets.main.output testmodClientImplementation sourceSets.main.output testmodClientImplementation sourceSets.client.output testmodClientImplementation sourceSets.testmod.output testImplementation "net.fabricmc:fabric-loader-junit:${project.loader_version}" testImplementation sourceSets.testmodClient.output testImplementation 'org.mockito:mockito-core:5.13.0' } test { useJUnitPlatform() afterEvaluate { // See: https://github.com/FabricMC/fabric-loader/pull/585 def classPathGroups = loom.mods.stream() .map { modSettings -> SourceSetHelper.getClasspath(modSettings, getProject()).stream() .map(File.&getAbsolutePath) .collect(Collectors.joining(File.pathSeparator)) } .collect(Collectors.joining(File.pathSeparator+File.pathSeparator)) systemProperty("fabric.classPathGroups", classPathGroups) } } tasks.withType(ProcessResources).configureEach { inputs.property "version", project.version filesMatching("fabric.mod.json") { expand "version": project.version } } spotless { lineEndings = com.diffplug.spotless.LineEnding.UNIX java { licenseHeaderFile(rootProject.file("HEADER")) removeUnusedImports() importOrder('java', 'javax', '', 'net.minecraft', 'net.fabricmc') indentWithTabs() trimTrailingWhitespace() } } checkstyle { configFile = rootProject.file("checkstyle.xml") toolVersion = "10.12.1" } tasks.withType(AbstractArchiveTask).configureEach { preserveFileTimestamps = false reproducibleFileOrder = true } remoteSign { sign remapJar } // Run this task after updating minecraft to regenerate any required resources tasks.register('generateResources') { group = "fabric" } tasks.register('testmodJar', Jar) { from sourceSets.testmod.output from sourceSets.testmodClient.output destinationDirectory = new File(project.buildDir, "devlibs") archiveClassifier = "testmod" } [jar, sourcesJar].each { it.from(rootProject.file("LICENSE")) { rename { "${it}-${project.base.archivesName.get()}"} } } if (file("src/client").exists() && !file("src/main").exists()) { remapJar { additionalClientOnlyEntries.add("LICENSE-${project.base.archivesName.get()}") } remapSourcesJar { additionalClientOnlyEntries.add("LICENSE-${project.base.archivesName.get()}") } } tasks.register('remapTestmodJar', net.fabricmc.loom.task.RemapJarTask) { dependsOn testmodJar input = testmodJar.archiveFile archiveClassifier = "testmod" addNestedDependencies = false includesClientOnlyClasses = true clientOnlySourceSetName = sourceSets.testmodClient.name classpath.from(sourceSets.testmodClient.compileClasspath) } build.dependsOn remapTestmodJar tasks.register('validateMixinNames', net.fabricmc.loom.task.ValidateMixinNameTask) { source(sourceSets.main.output) source(sourceSets.client.output) source(sourceSets.testmod.output) } // Apply to each valid subproject. apply from: rootProject.file('gradle/package-info.gradle') apply from: rootProject.file('gradle/validate-annotations.gradle') } remapTestmodJar { def testModJarTasks = [] subprojects { if (metaProjects.contains(it.name) || !(it.file("src/testmod").exists() || it.file("src/testmodClient").exists())) { return } testModJarTasks += it.tasks.remapTestmodJar } nestedJars.setFrom(testModJarTasks) addNestedDependencies = true clientOnlySourceSetName = sourceSets.testmodClient.name } // Apply auxiliary buildscripts to submodules // This must be done after all plugins are applied to subprojects apply from: "gradle/module-validation.gradle" apply from: "gradle/module-versioning.gradle" loom { accessWidenerPath = file("gradle/javadoc.accesswidener") } javadoc { options { source = "21" encoding = "UTF-8" charSet = "UTF-8" memberLevel = JavadocMemberLevel.PACKAGE links( "https://maven.fabricmc.net/docs/yarn-${rootProject.minecraft_version}${project.yarn_version}/" ) // Disable the crazy super-strict doclint tool in Java 8 addStringOption("Xdoclint:none", "-quiet") tags( 'apiNote:a:API Note:', 'implSpec:a:Implementation Requirements:', 'implNote:a:Implementation Note:' ) } allprojects.each { if (metaProjects.contains(it.name)) { return } source(it.sourceSets.main.allJava) source(it.sourceSets.client.allJava) } classpath = files(sourceSets.main.compileClasspath, sourceSets.client.compileClasspath) include("**/api/**") failOnError true } tasks.register('javadocJar', Jar) { dependsOn javadoc from javadoc.destinationDir //Set as `fatjavadoc` to prevent an ide form trying to use this javadoc, over using the modules javadoc archiveClassifier = "fatjavadoc" } build.dependsOn javadocJar loom { runs { gametest { inherit testmodServer name "Game Test" // Enable the gametest runner vmArg "-Dfabric-api.gametest" vmArg "-Dfabric-api.gametest.report-file=${project.buildDir}/junit.xml" runDir "build/gametest" } autoTestServer { inherit testmodServer name "Auto Test Server" vmArg "-Dfabric.autoTest" } autoTestClient { inherit testmodClient name "Auto Test Client" vmArg "-Dfabric.autoTest" vmArg "-Dfabric-tag-conventions-v2.missingTagTranslationWarning=fail" vmArg "-Dfabric-tag-conventions-v1.legacyTagWarning=fail" } // Create duplicate tasks for this, as jacoco slows things down a bit gametestCoverage { inherit gametest name "Game Test Coverage" ideConfigGenerated = false } autoTestClientCoverage { inherit autoTestClient name "Auto Test Client Coverage" ideConfigGenerated = false } } } test.dependsOn runGametest def coverageTasks = [ runGametestCoverage, runAutoTestClientCoverage ] jacoco { coverageTasks.forEach { applyTo it } } tasks.register('coverage', JacocoReport) { dependsOn coverageTasks coverageTasks.forEach { executionData it } // Add all source as input allprojects { p -> if (p.path.startsWith(":deprecated") || metaProjects.contains(p.name)) { return } sourceSets p.sourceSets.main, p.sourceSets.client, p.sourceSets.testmod, p.sourceSets.testmodClient } // Exclude mixins classDirectories.setFrom(files(classDirectories.files.collect { fileTree(dir: it, exclude: '**/mixin/**') })) } configurations { productionRuntime { extendsFrom configurations.minecraftLibraries extendsFrom configurations.loaderLibraries extendsFrom configurations.minecraftRuntimeLibraries } productionRuntimeServer } dependencies { productionRuntime "net.fabricmc:fabric-loader:${project.loader_version}" productionRuntime "net.fabricmc:intermediary:${project.minecraft_version}" productionRuntimeServer "net.fabricmc:fabric-installer:${project.installer_version}:server" } import net.fabricmc.loom.util.Platform // This is very far beyond loom's API if you copy this, you're on your own. tasks.register('runProductionAutoTestClient', JavaExec) { dependsOn remapJar, remapTestmodJar, downloadAssets classpath.from configurations.productionRuntime mainClass = "net.fabricmc.loader.impl.launch.knot.KnotClient" workingDir = file("run") doFirst { classpath.from loom.minecraftProvider.minecraftClientJar workingDir.mkdirs() args( "--assetIndex", loom.minecraftProvider.versionInfo.assetIndex().fabricId(loom.minecraftProvider.minecraftVersion()), "--assetsDir", new File(loom.files.userCache, "assets").absolutePath, "--gameDir", workingDir.absolutePath ) if (Platform.CURRENT.operatingSystem.isMacOS()) { jvmArgs( "-XstartOnFirstThread" ) } jvmArgs( "-Dfabric.addMods=${remapJar.archiveFile.get().asFile.absolutePath}${File.pathSeparator}${remapTestmodJar.archiveFile.get().asFile.absolutePath}", "-Dfabric.autoTest", "-Dfabric-tag-conventions-v2.missingTagTranslationWarning=fail", "-Dfabric-tag-conventions-v1.legacyTagWarning=fail" ) jvmArgs(debugArgs) } } tasks.register('serverPropertiesJar', Jar) { def propsFile = file("build/tmp/install.properties") doFirst { propsFile.text = """\ fabric-loader-version=${project.loader_version} game-version=${project.minecraft_version} """.stripMargin().stripIndent() } archiveFileName = "test-server-properties.jar" destinationDirectory = file("build/tmp") from(propsFile) } tasks.register('runProductionAutoTestServer', JavaExec) { dependsOn remapJar, remapTestmodJar, serverPropertiesJar classpath.from configurations.productionRuntimeServer, serverPropertiesJar mainClass = "net.fabricmc.installer.ServerLauncher" workingDir = file("run") doFirst { workingDir.mkdirs() jvmArgs( "-Dfabric.addMods=${remapJar.archiveFile.get().asFile.absolutePath}${File.pathSeparator}${remapTestmodJar.archiveFile.get().asFile.absolutePath}", "-Dfabric.autoTest", ) jvmArgs(debugArgs) args("nogui") } } // Format all the gradle files spotless { groovyGradle { target 'src/**/*.gradle', '*.gradle', 'gradle/*.gradle' greclipse() } } def addPomMetadataInformation(Project project, MavenPom pom) { def modJsonFile = project.file("src/main/resources/fabric.mod.json") if (!modJsonFile.exists()) { modJsonFile = project.file("src/client/resources/fabric.mod.json") } def modJson = new JsonSlurper().parse(modJsonFile) pom.name = modJson.name pom.url = "https://github.com/FabricMC/fabric/tree/HEAD/${project.rootDir.relativePath(project.projectDir)}" pom.description = modJson.description pom.licenses { license { name = "Apache-2.0" url = "https://github.com/FabricMC/fabric/blob/HEAD/LICENSE" } } pom.developers { developer { name = "FabricMC" url = "https://fabricmc.net/" } } pom.scm { connection = "scm:git:https://github.com/FabricMC/fabric.git" url = "https://github.com/FabricMC/fabric" developerConnection = "scm:git:git@github.com:FabricMC/fabric.git" } pom.issueManagement { system = "GitHub" url = "https://github.com/FabricMC/fabric/issues" } } subprojects { if (metaProjects.contains(it.name)) { return } base { archivesName = project.name } dependencies { testmodImplementation sourceSets.main.output // Make all modules depend on the gametest api (and thus res loader) to try and promote its usage. if (project.name != "fabric-gametest-api-v1") { testmodImplementation project(path: ':fabric-gametest-api-v1', configuration: 'namedElements') testmodClientImplementation project(":fabric-gametest-api-v1").sourceSets.client.output testmodImplementation project(path: ':fabric-resource-loader-v0', configuration: 'namedElements') testmodClientImplementation project(":fabric-resource-loader-v0").sourceSets.client.output } // Make all testmods run with registry-sync-v0 as it is required to register new objects. if (project.name != "fabric-registry-sync-v0") { testmodRuntimeOnly project(path: ':fabric-registry-sync-v0', configuration: 'namedElements') testmodClientImplementation project(":fabric-registry-sync-v0").sourceSets.client.output } } publishing { publications { mavenJava(MavenPublication) { pom { addPomMetadataInformation(project, pom) } artifact(signRemapJar.output) { builtBy(signRemapJar) } artifact(remapSourcesJar) { builtBy remapSourcesJar } } } } // We manually handle the pom generation loom.disableDeprecatedPomGeneration(publishing.publications.mavenJava) javadoc.enabled = false } publishing { publications { mavenJava(MavenPublication) { artifact(signRemapJar.output) { builtBy(signRemapJar) } artifact(sourcesJar) { builtBy remapSourcesJar } artifact javadocJar artifact remapTestmodJar pom { addPomMetadataInformation(rootProject, pom) } pom.withXml { def depsNode = asNode().appendNode("dependencies") subprojects.each { // The maven BOM containing all of the deprecated modules is added manually below. if (it.path.startsWith(":deprecated") || metaProjects.contains(it.name)) { return } def depNode = depsNode.appendNode("dependency") depNode.appendNode("groupId", it.group) depNode.appendNode("artifactId", it.name) depNode.appendNode("version", it.version) depNode.appendNode("scope", "compile") } // Depend on the deprecated BOM to allow opting out of deprecated modules. def depNode = depsNode.appendNode("dependency") depNode.appendNode("groupId", group) depNode.appendNode("artifactId", "fabric-api-deprecated") depNode.appendNode("version", version) depNode.appendNode("scope", "compile") } } } } // Required until the deprecation is removed. Fabric API's main jar that is published to maven does not contain sub modules. loom.disableDeprecatedPomGeneration(publishing.publications.mavenJava) void setupRepositories(RepositoryHandler repositories) { //repositories.mavenLocal() // uncomment for testing def ENV = System.getenv() if (ENV.MAVEN_URL) { repositories.maven { url ENV.MAVEN_URL if (ENV.MAVEN_USERNAME) { credentials { username ENV.MAVEN_USERNAME password ENV.MAVEN_PASSWORD } } } } } subprojects.each { if (metaProjects.contains(it.name)) { return } remapJar.dependsOn("${it.path}:remapJar") } // These modules are not included in the fat jar, maven will resolve them via the pom. def devOnlyModules = ["fabric-gametest-api-v1",] dependencies { afterEvaluate { subprojects.each { if (metaProjects.contains(it.name)) { return } api project(path: "${it.path}", configuration: "namedElements") clientImplementation project("${it.path}:").sourceSets.client.output testmodImplementation project("${it.path}:").sourceSets.testmod.output testmodClientImplementation project("${it.path}:").sourceSets.testmodClient.output } } } remapJar { afterEvaluate { subprojects.each { if (it.name in devOnlyModules || metaProjects.contains(it.name)) { return } // Include the signed or none signed jar from the sub project. nestedJars.from project("${it.path}").tasks.getByName("signRemapJar") } } } publishMods { file = signRemapJar.output changelog = providers.environmentVariable("CHANGELOG").getOrElse("No changelog provided") type = project.prerelease == "true" ? BETA : STABLE displayName = "[${project.minecraft_version}] Fabric API $project.version" modLoaders.add("fabric") dryRun = providers.environmentVariable("CURSEFORGE_API_KEY").getOrNull() == null curseforge { accessToken = providers.environmentVariable("CURSEFORGE_API_KEY") projectId = "306612" minecraftVersions.add(project.curseforge_minecraft_version) } modrinth { accessToken = providers.environmentVariable("MODRINTH_TOKEN") projectId = "P7dR8mSH" minecraftVersions.add(project.minecraft_version) } github { accessToken = providers.environmentVariable("GITHUB_TOKEN") repository = providers.environmentVariable("GITHUB_REPOSITORY").getOrElse("FabricMC/dryrun") commitish = providers.environmentVariable("GITHUB_REF_NAME").getOrElse("dryrun") } } assemble.dependsOn signRemapJar import java.util.stream.Collectors // A task to ensure that the version being released has not already been released. tasks.register('checkVersion') { doFirst { def xml = new URL("https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api/maven-metadata.xml").text def metadata = new XmlSlurper().parseText(xml) def versions = metadata.versioning.versions.version*.text(); if (versions.contains(version)) { throw new RuntimeException("${version} has already been released!") } } } tasks.publishMods.dependsOn checkVersion publish.mustRunAfter checkVersion