buildscript { repositories { maven { name = 'Fabric' url = 'https://maven.fabricmc.net/' } mavenCentral() maven { name = 'CurseGradle' url = 'https://gitlab.com/api/v4/projects/32776914/packages/maven' } gradlePluginPortal() if (project.hasProperty("libjf_version")) { maven { name = 'JF Commons' url = 'https://gitlab.com/api/v4/projects/35745143/packages/maven' } maven { name = 'LibJF' url = 'https://gitlab.com/api/v4/projects/25805200/packages/maven' } } mavenLocal() } dependencies { classpath "net.fabricmc:fabric-loom:1.0-SNAPSHOT" classpath "org.ajoberstar.grgit:grgit-gradle:5.0.0" classpath "com.modrinth.minotaur:Minotaur:2.3.1" classpath "io.gitlab.jfronny:CurseGradle:1.4.0-1642087331626" classpath "gradle.plugin.com.github.johnrengelman:shadow:7.1.2" if (project.hasProperty("libjf_version")) classpath "io.gitlab.jfronny.libjf:libjf-config-compiler-plugin:${project.getProperty("libjf_version")}" } } ext.curseforgeAvailable = project.hasProperty("curseforge_id") ext.modrinthAvailable = project.hasProperty("modrinth_id") ext.devOnlyModules = project.hasProperty("dev_only_module") ? project.getProperty("dev_only_module").split(", ") : [] ext.nonModSubprojects = project.hasProperty("non_mod_project") ? project.getProperty("non_mod_project").split(", ") : [] ext.injectConfig = project.hasProperty("libjf_version") if (ext.injectConfig) ext.configCompilerVersion = project.getProperty("libjf_version") apply plugin: 'idea' apply plugin: 'java-library' apply plugin: 'maven-publish' if (ext.curseforgeAvailable) apply plugin: com.matthewprenger.cursegradle.CurseGradlePlugin if (ext.modrinthAvailable) apply plugin: com.modrinth.minotaur.Minotaur if (ext.injectConfig) apply plugin: io.gitlab.jfronny.libjf.config.plugin.ConfigPlugin apply plugin: org.ajoberstar.grgit.gradle.GrgitPlugin enum VersionType { release, beta, alpha } // Fetch changelog def changelogStr = "" ext.currentVer = "0.0.0+nogit" ext.currentType = VersionType.alpha if (grgit != null) { ext.currentVer = "0.0.0+notag" grgit.open(dir: project.projectDir.toString()) def tagList = grgit.tag.list() tagList.sort((left, right) -> right.commit.dateTime.compareTo(left.commit.dateTime)) if (tagList.size() >= 1) { if (tagList.get(0).fullMessage != null) { changelogStr += tagList.get(0).fullMessage + "\n" } ext.currentType = VersionType.release ext.currentVer = tagList.get(0).getName() switch (ext.currentVer[0]) { case 'v': ext.currentVer = ext.currentVer.substring(1) break case 'b': ext.currentVer = ext.currentVer.substring(1) ext.currentType = VersionType.beta break case 'a': ext.currentVer = ext.currentVer.substring(1) ext.currentType = VersionType.alpha break } def commits = new ArrayList<>(tagList.size() >= 2 ? grgit.log{range(tagList.get(1).fullName, tagList.get(0).fullName)} : grgit.log(includes: [grgit.tag.list().get(0).fullName])) Collections.reverse(commits) changelogStr += "Commits in " + ext.currentType.toString() + " " + ext.currentVer + ":\n" for (def commit : commits) { changelogStr += "- " + commit.shortMessage + "\n" } } } if (changelogStr == "") { changelogStr = "No changelog" } if (!project.hasProperty("release")) { ext.currentVer += "-" + Instant.now().getEpochSecond() } println(changelogStr) if (!project.hasProperty("modrinth_required_dependencies")) project.ext.modrinth_required_dependencies = "" else project.ext.modrinth_required_dependencies = project.modrinth_required_dependencies if (!project.hasProperty("modrinth_optional_dependencies")) project.ext.modrinth_optional_dependencies = "" else project.ext.modrinth_optional_dependencies = project.modrinth_optional_dependencies if (!project.hasProperty("curseforge_required_dependencies")) project.ext.curseforge_required_dependencies = "" else project.ext.curseforge_required_dependencies = project.curseforge_required_dependencies if (!project.hasProperty("curseforge_optional_dependencies")) project.ext.curseforge_optional_dependencies = "" else project.ext.curseforge_optional_dependencies = project.curseforge_optional_dependencies task deployDebug() { } task deployRelease() { } tasks.deployRelease.dependsOn(tasks.deployDebug) allprojects { if (project.name in rootProject.nonModSubprojects) return apply plugin: "java-library" apply plugin: "maven-publish" apply plugin: net.fabricmc.loom.bootstrap.LoomGradlePluginBootstrap apply plugin: com.github.jengelman.gradle.plugins.shadow.ShadowPlugin if (rootProject.injectConfig) apply plugin: io.gitlab.jfronny.libjf.config.plugin.ConfigPlugin tasks.withType(JavaCompile).configureEach { it.options.encoding = "UTF-8" it.options.release = 17 } if (project.hasProperty("archives_base_name")) archivesBaseName = project.archives_base_name group = project.maven_group version = "$rootProject.currentVer" loom { runtimeOnlyLog4j = true splitEnvironmentSourceSets() } sourceSets { testmod { compileClasspath += main.compileClasspath runtimeClasspath += main.runtimeClasspath compileClasspath += client.compileClasspath runtimeClasspath += client.runtimeClasspath } } dependencies { minecraft "com.mojang:minecraft:${project.minecraft_version}" if (project.hasProperty("yarn_mappings")) { mappings "net.fabricmc:yarn:${project.minecraft_version}+${project.yarn_mappings}:v2" } else { mappings loom.officialMojangMappings() } modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" testmodImplementation sourceSets.main.output testmodImplementation sourceSets.client.output } repositories { maven { name = 'TerraformersMC' url = 'https://maven.terraformersmc.com/' } maven { name = 'LibJF' url = 'https://gitlab.com/api/v4/projects/25805200/packages/maven' } maven { name = 'JF Gson' url = 'https://gitlab.com/api/v4/projects/35030495/packages/maven' } maven { name = 'JF Commons' url = 'https://gitlab.com/api/v4/projects/35745143/packages/maven' } maven { name = 'JF FLoader' url = 'https://gitlab.com/api/v4/projects/36014652/packages/maven' } mavenCentral() mavenLocal() } configurations { dev } jar { archiveClassifier = 'dev' } var shadowJarInput = jar if (rootProject.injectConfig) { task injectCompiledConfig(type: io.gitlab.jfronny.libjf.config.plugin.ConfigInjectTask, dependsOn: jar) { from jar modId = archivesBaseName archiveClassifier = 'config-inject' destinationDirectory = file("${project.buildDir}/devlibs") } shadowJarInput = injectCompiledConfig } task completeJar(type: com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar, dependsOn: shadowJarInput) { from shadowJarInput configurations = [ project.configurations.shadow ] archiveClassifier = 'shadow' destinationDirectory = file("${project.buildDir}/devlibs") } afterEvaluate { remapJar { dependsOn completeJar input = completeJar.archiveFile archiveFileName = "${archivesBaseName}-${project.version}.jar" } artifacts { dev file: jar.archiveFile.get().asFile, type: "jar", builtBy: jar } processResources { inputs.property 'version', project.version filesMatching('fabric.mod.json') { expand 'version': project.version } } project.rootProject.allprojects.each { sub -> if (!(sub.name in rootProject.nonModSubprojects)) { loom.mods.register(sub.name, { sourceSet sub.sourceSets.main sourceSet sub.sourceSets.client }) loom.mods.register(sub.name + "-testmod", { sourceSet sub.sourceSets.testmod }) } } } java { withSourcesJar() } tasks.withType(AbstractArchiveTask) { preserveFileTimestamps = false reproducibleFileOrder = true } task remapMavenJar(type: net.fabricmc.loom.task.RemapJarTask, dependsOn: completeJar) { input = completeJar.archiveFile archiveFileName = "${archivesBaseName}-${project.version}-maven.jar" addNestedDependencies = false } build.dependsOn remapMavenJar task testmodJar(type: Jar) { //TODO include deps from sourceSets.testmod.output destinationDirectory = new File(project.buildDir, "devlibs") archiveClassifier = "testmod" } task remapTestmodJar(type: net.fabricmc.loom.task.RemapJarTask, dependsOn: testmodJar) { input = testmodJar.archiveFile archiveClassifier = "testmod" addNestedDependencies = false } build.dependsOn remapTestmodJar publishing { publications { mavenJava(MavenPublication) { artifact(remapMavenJar) { builtBy remapMavenJar } artifact(sourcesJar) { builtBy remapSourcesJar } } } repositories { mavenLocal() if (project.hasProperty("maven")) { maven { url = project.getProperty("maven") name = "dynamic" credentials(HttpHeaderCredentials) { name = "Job-Token" value = System.getenv().CI_JOB_TOKEN } authentication { header(HttpHeaderAuthentication) } } } } } tasks.publish.dependsOn(tasks.build) rootProject.tasks.deployDebug.dependsOn(tasks.publish) } subprojects { if (project.name in rootProject.nonModSubprojects) return javadoc.enabled = false dependencies { testmodImplementation sourceSets.main.output } afterEvaluate { genClientOnlySources.enabled = false genCommonSources.enabled = false unpickClientOnlyJar.enabled = false unpickCommonJar.enabled = false rootProject.dependencies { api project(path: project.path, configuration: "shadow") clientImplementation project.sourceSets.client.output testmodImplementation project.sourceSets.testmod.output if (!(project.name in rootProject.devOnlyModules)) { include project } } } } sourceSets { testmod } def readmeFile = rootProject.file("README.md") if (ext.modrinthAvailable) { modrinth { token = System.getenv().MODRINTH_API_TOKEN projectId = project.modrinth_id versionName = "[${project.minecraft_version}] ${version}" versionType = project.ext.currentType.toString() changelog = changelogStr uploadFile = remapJar gameVersions = ["${project.minecraft_version}"] loaders = ['fabric'] dependencies { if (!project.ext.modrinth_required_dependencies.isEmpty()) { project.ext.modrinth_required_dependencies.split(", ").each { String dep -> required.project dep } } if (!project.ext.modrinth_optional_dependencies.isEmpty()) { project.ext.modrinth_optional_dependencies.split(", ").each { String dep -> optional.project dep } } } if (readmeFile.exists()) { syncBodyFrom = readmeFile.text + "\n\n[![Contact](https://img.shields.io/badge/-Contact-informational)](https://jfronny.gitlab.io/contact.html)" } } tasks.deployRelease.dependsOn(tasks.modrinth) if (readmeFile.exists()) { tasks.deployRelease.dependsOn(tasks.modrinthSyncBody) } } if (ext.curseforgeAvailable) { curseforge { if (System.getenv().CURSEFORGE_API_TOKEN) { apiKey = System.getenv().CURSEFORGE_API_TOKEN } else { println "No CURSEFORGE_API_TOKEN specified" } project { id = project.curseforge_id releaseType = 'release' addGameVersion "Fabric" addGameVersion "${project.minecraft_version}" changelog = changelogStr mainArtifact(file("${project.buildDir}/libs/${archivesBaseName}-${version}.jar")) mainArtifact.displayName = "[${project.minecraft_version}] ${version}" if (!project.ext.curseforge_required_dependencies.isEmpty() || !project.ext.curseforge_optional_dependencies.isEmpty()) { relations { if (!project.ext.curseforge_required_dependencies.isEmpty()) { project.ext.curseforge_required_dependencies.split(", ").each { String dep -> requiredDependency dep } } if (!project.ext.curseforge_optional_dependencies.isEmpty()) { project.ext.curseforge_optional_dependencies.split(", ").each { String dep -> optionalDependency dep } } } } releaseType = project.ext.currentType.toString() afterEvaluate { uploadTask.dependsOn(build) } } options { forgeGradleIntegration = false } } tasks.deployRelease.dependsOn(tasks.curseforge) }