Skip to content

Commit

Permalink
Revert to architectury for older versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Erdragh committed May 27, 2024
1 parent 3a9d0b8 commit 43c4392
Show file tree
Hide file tree
Showing 27 changed files with 309 additions and 449 deletions.
118 changes: 94 additions & 24 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@ import org.jetbrains.kotlin.gradle.utils.extendsFrom
import java.nio.charset.StandardCharsets
import java.text.SimpleDateFormat
import java.util.*
import dev.architectury.plugin.ArchitectPluginExtension
import net.fabricmc.loom.api.LoomGradleExtensionAPI
import net.fabricmc.loom.task.RemapJarTask
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

plugins {
// This is an Architectury repository, as such the relevant plugins are needed
id("architectury-plugin") version "3.4-SNAPSHOT"
id("dev.architectury.loom") version "1.5-SNAPSHOT" apply false
// The shadow plugin is used by the fabric subproject to include dependencies
// I'm temporarily using a fork of the original plugin to resolve "Unsupported java classfile major version 65"
// see: https://github.com/johnrengelman/shadow/issues/911
Expand All @@ -14,19 +21,23 @@ plugins {
// For generating documentation based on comments in the code
id("org.jetbrains.dokka") version "1.9.10"
java
// Required for NeoGradle
id("org.jetbrains.gradle.plugin.idea-ext") version "1.1.7"
// For publishing the mod
id("me.modmuss50.mod-publish-plugin") version "0.5.1"
}

val minecraftVersion: String by project

architectury {
minecraft = minecraftVersion
}

repositories {
mavenCentral()
}

subprojects {
apply(plugin = "dev.architectury.loom")
apply(plugin = "architectury-plugin")
apply(plugin = "java")
apply(plugin = "kotlin")
apply(plugin = "org.jetbrains.dokka")
Expand All @@ -45,14 +56,18 @@ subprojects {
archivesName.set("$modId-$modLoader-$minecraftVersion")
}

configure<LoomGradleExtensionAPI> {
silentMojangMappingsLicense()
}

extensions.configure<JavaPluginExtension> {
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
withSourcesJar()
}

repositories {
mavenCentral()
maven(url = "https://maven.neoforged.net/releases/")
maven(url = "https://maven.architectury.dev/")
maven("https://repo.spongepowered.org/repository/maven-public/") { name = "Sponge / Mixin" }
maven("https://maven.blamejared.com") { name = "BlameJared Maven (JEI / CraftTweaker / Bookshelf)" }
// For the parchment mappings
Expand All @@ -79,25 +94,43 @@ subprojects {
val shadowBotDep by configurations.creating {
isTransitive = true
}
// Configuration for JiJ-ed dependencies
val includeBotDep by configurations.creating {
isTransitive = false
// This shadowCommon configuration is used to shade the
// common project
val shadowCommon by configurations.creating {
isCanBeConsumed = false
isCanBeResolved = true
}
// Configuration for libraries that are needed at runtime
val runtimeLib by configurations.creating {
isTransitive = true
}
configurations.implementation.extendsFrom(configurations.named("shadowBotDep"))
configurations.implementation.extendsFrom(configurations.named("includeBotDep"))
configurations.implementation.extendsFrom(configurations.named("runtimeLib"))

dependencies {
// Minecraft Mod dependencies
"minecraft"("::$minecraftVersion")

@Suppress("UnstableApiUsage")
"mappings"(project.the<LoomGradleExtensionAPI>().layered {
val parchmentVersion: String by project

officialMojangMappings()

parchment(
create(
group = "org.parchmentmc.data",
name = "parchment-$minecraftVersion",
version = parchmentVersion
)
)
})

runtimeLib("org.xerial:sqlite-jdbc:$sqliteJDBCVersion")
includeBotDep("org.xerial:sqlite-jdbc:$sqliteJDBCVersion")
if (!isCommon) "include"("org.xerial:sqlite-jdbc:$sqliteJDBCVersion")

runtimeLib("org.commonmark:commonmark:$commonmarkVersion")
includeBotDep("org.commonmark:commonmark:$commonmarkVersion")

if (!isCommon) "include"("org.commonmark:commonmark:$commonmarkVersion")

arrayOf(
// Library used to communicate with Discord, see https://jda.wiki
Expand Down Expand Up @@ -134,6 +167,9 @@ subprojects {
}

tasks.jar {
// Results in the not remapped jars having a -dev at the end
archiveClassifier.set("dev")

from(rootProject.file("LICENSE")) {
rename { "${it}_$modId" }
}
Expand All @@ -157,34 +193,28 @@ subprojects {
tasks.processResources {
val version: String by project
val group: String by project
val minecraftVersionRange: String by project
val fabricApiVersion: String by project
val fabricLoaderVersion: String by project
val fabricKotlinVersion: String by project
val neoVersion: String by project
val neoVersionRange: String by project
val kffLoaderRange: String by project
val license: String by project
val description: String by project
val credits: String by project
val title: String by project

val expandProps = mapOf(
"version" to version,
"group" to group, //Else we target the task's group.
"minecraft_version" to minecraftVersion,
"minecraft_version_range" to minecraftVersionRange,
"fabric_version" to fabricApiVersion,
"fabric_loader_version" to fabricLoaderVersion,
"fabric_kotlin_version" to fabricKotlinVersion,
"neoforge_version" to neoVersion,
"neoforge_loader_version_range" to neoVersionRange,
"kff_loader_range" to kffLoaderRange,
"mod_name" to modName,
"mod_author" to modAuthor,
"mod_id" to modId,
"license" to license,
"description" to description,
"credits" to credits
"credits" to credits,
"title" to title
)

filesMatching(listOf("pack.mcmeta", "*.mixins.json", "META-INF/mods.toml", "fabric.mod.json")) {
Expand All @@ -193,12 +223,52 @@ subprojects {
inputs.properties(expandProps)
}

if (isCommon) {
sourceSets.main.get().resources.srcDir("src/main/generated/resources")
} else {
dependencies {
implementation(project(":common"))
if (!isCommon) {
apply(plugin = "io.github.goooler.shadow")

configure<ArchitectPluginExtension> {
platformSetupLoomIde()
}

tasks {
named<ShadowJar>("shadowJar") {
archiveClassifier.set("dev-shadow")

configurations = listOf(shadowBotDep, shadowCommon)

// This transforms the service files to make relocated Exposed work (see: https://github.com/JetBrains/Exposed/issues/1353)
mergeServiceFiles()

// Relocating Exposed somewhere different so other mods not doing that don't run into issues (e.g. Ledger)
relocate("org.jetbrains.exposed", "dev.erdragh.shadowed.org.jetbrains.exposed")

// Forge restricts loading certain classes for security reasons.
// Luckily, shadow can relocate them to a different package.
relocate("org.apache.commons.collections4", "dev.erdragh.shadowed.org.apache.commons.collections4")

// Relocating jackson to prevent incompatibilities with other mods also bundling it (e.g. GroovyModLoader on Forge)
relocate("com.fasterxml.jackson", "dev.erdragh.shadowed.com.fasterxml.jackson")

exclude(".cache/**") //Remove datagen cache from jar.
exclude("**/astralbot/datagen/**") //Remove data gen code from jar.
exclude("**/org/slf4j/**")

exclude("kotlinx/**")
exclude("_COROUTINE/**")
exclude("**/org/jetbrains/annotations/*")
exclude("**/org/intellij/**")
}

named<RemapJarTask>("remapJar") {
inputFile.set(named<ShadowJar>("shadowJar").get().archiveFile)
dependsOn("shadowJar")
// Results in the remapped jar not having any extra bit in
// its file name, identifying it as the main distribution
archiveClassifier.set(null as String?)
}
}
} else {
sourceSets.main.get().resources.srcDir("src/main/generated/resources")
}

// Disables Gradle's custom module metadata from being published to maven. The
Expand Down
36 changes: 7 additions & 29 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,36 +1,14 @@
plugins {
idea
java
`maven-publish`
id ("org.spongepowered.gradle.vanilla") version "0.2.1-SNAPSHOT"
}

val minecraftVersion: String by project
val modId: String by project

minecraft {
version(minecraftVersion)
if (file("src/main/resources/${modId}.accesswidener").exists())
accessWideners(file("src/main/resources/${modId}.accesswidener"))
architectury {
val enabledPlatforms: String by rootProject
common(enabledPlatforms.split(","))
}

dependencies {
val fabricLoaderVersion: String by project
val forgeConfigAPIVersion: String by project
// We depend on fabric loader here to use the fabric @Environment annotations and get the mixin dependencies
// Do NOT use other classes from fabric loader
modImplementation("net.fabricmc:fabric-loader:${fabricLoaderVersion}")

api("fuzs.forgeconfigapiport:forgeconfigapiport-common-neoforgeapi:$forgeConfigAPIVersion")
compileOnly("org.spongepowered:mixin:0.8.5")
}

publishing {
publications {
register("mavenJava", MavenPublication::class) {
artifactId = base.archivesName.get()
from(components["java"])
}
}

repositories {
maven("file://${System.getenv("local_maven")}")
}
api("fuzs.forgeconfigapiport:forgeconfigapiport-common:$forgeConfigAPIVersion")
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package dev.erdragh.astralbot.config

import dev.erdragh.astralbot.LOGGER
import dev.erdragh.astralbot.commands.discord.allCommands
import net.neoforged.neoforge.common.ModConfigSpec
import net.minecraftforge.common.ForgeConfigSpec
import java.net.URL

/**
Expand All @@ -12,89 +12,89 @@ import java.net.URL
* @author Erdragh
*/
object AstralBotConfig {
val SPEC: ModConfigSpec
val SPEC: ForgeConfigSpec

/**
* If the `DISCORD_TOKEN` environment variable isn't set, the bot will
* look for a token in this config option.
*/
val DISCORD_TOKEN: ModConfigSpec.ConfigValue<String>
val DISCORD_TOKEN: ForgeConfigSpec.ConfigValue<String>

/**
* Whether the default whitelisting process is respected or ignored.
* Setting this to `true` will *force* every user who wants to join
* the server to link their account, even Operators.
*/
val REQUIRE_LINK_FOR_WHITELIST: ModConfigSpec.BooleanValue
val REQUIRE_LINK_FOR_WHITELIST: ForgeConfigSpec.BooleanValue

/**
* The link to the Discord servers where users can run the /link command.
* Gets used when formatting the message shown to users who try to log in
* without being whitelisted.
*/
val DISCORD_LINK: ModConfigSpec.ConfigValue<String>
val DISCORD_LINK: ForgeConfigSpec.ConfigValue<String>

/**
* The ID of the discord channel where the messages are synchronized
*/
val DISCORD_CHANNEL: ModConfigSpec.ConfigValue<Long>
val DISCORD_CHANNEL: ForgeConfigSpec.ConfigValue<Long>

/**
* The ID of the Discord Guild (server) where this bot will be active.
* This is used to get the chat sync channel etc.
*/
val DISCORD_GUILD: ModConfigSpec.ConfigValue<Long>
val DISCORD_GUILD: ForgeConfigSpec.ConfigValue<Long>

/**
* The ID of the Discord role given to linked members
*/
val DISCORD_ROLE: ModConfigSpec.ConfigValue<Long>
val DISCORD_ROLE: ForgeConfigSpec.ConfigValue<Long>

/**
* If this is set to true the message sent into the Minecraft chat
* will be clickable and take you to the relevant message on Discord
*/
val CLICKABLE_MESSAGES: ModConfigSpec.BooleanValue
val CLICKABLE_MESSAGES: ForgeConfigSpec.BooleanValue

/**
* If this is on the embeds and attached files on a message will be
* handled and possibly displayed in messages sent to the players
*/
val HANDLE_EMBEDS: ModConfigSpec.BooleanValue
val HANDLE_EMBEDS: ForgeConfigSpec.BooleanValue

/**
* If this is on embeds that have a URL associated with them will
* be clickable.
*/
val CLICKABLE_EMBEDS: ModConfigSpec.BooleanValue
val CLICKABLE_EMBEDS: ForgeConfigSpec.BooleanValue

/**
* List of Strings containing the URLs that are blocked by default.
* If you read this and want to add more to the default list, feel
* free to open an Issue or Pull Request.
*/
private val URL_BLOCKLIST: ModConfigSpec.ConfigValue<List<String>>
private val URL_BLOCKLIST: ForgeConfigSpec.ConfigValue<List<String>>

/**
* List of the names of the commands that are enabled by default.
* On first startup of a server, it will be all available commands.
*/
val ENABLED_COMMANDS: ModConfigSpec.ConfigValue<List<String>>
val ENABLED_COMMANDS: ForgeConfigSpec.ConfigValue<List<String>>

/**
* Enables parsing Discord messages into Minecraft's Chat Components.
* This includes making links clickable, etc.
*/
val ENABLE_MARKDOWN_PARSING: ModConfigSpec.BooleanValue
val ENABLE_MARKDOWN_PARSING: ForgeConfigSpec.BooleanValue

/**
* Enables converting detected URLs into clickable links, requires
* [ENABLE_MARKDOWN_PARSING] to be enabled to do anything
*/
val ENABLE_AUTO_LINKS: ModConfigSpec.BooleanValue
val ENABLE_AUTO_LINKS: ForgeConfigSpec.BooleanValue

init {
val builder = ModConfigSpec.Builder()
val builder = ForgeConfigSpec.Builder()

builder.comment("AstralBot Config")

Expand Down
Loading

0 comments on commit 43c4392

Please sign in to comment.