Skip to content

Commit

Permalink
Merge pull request #43 from devOS-Sanity-Edition/fix/make-it-work-in-…
Browse files Browse the repository at this point in the history
…production

🦊 The fox took Yiski's balls away (sanity) then fed it all of the food (dependencies) we have
  • Loading branch information
asoji authored Aug 28, 2024
2 parents 1c317f2 + 4160621 commit 51c1314
Show file tree
Hide file tree
Showing 39 changed files with 495 additions and 222 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ bin/
.DS_Store

### Yiski Discord Bot ###
**/modules
**/run
**/config.toml
**/yiski1_config.toml
Expand Down
1 change: 0 additions & 1 deletion Writerside/snippets/yiski.metadata.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ configClass = ""

[module.packages]
databasePackage = ""
slashCommandsPackage = ""

[information]
id = ""
Expand Down
1 change: 0 additions & 1 deletion Writerside/snippets/yiski.metadata.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ configClass = "one.devos.yiski1.Yiski1Config"

[module.packages]
databasePackage = "one.devos.yiski1.tables"
slashCommandsPackage = "one.devos.yiski1.commands"

[information]
id = "yiski1"
Expand Down
5 changes: 1 addition & 4 deletions Writerside/topics/Modules-Metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,14 @@ information about itself.

### Packages

> Package paths are optional, but required if you're using anything related to Tables or Slash Commands
> Package paths are optional, but required if you're using anything related to Tables
{style="note"}

> Do not point these to a file, point it to the package containing the classes/objects.
`databasePackage`
: Your module's package for where all the SQL/Exposed SQL Tables are stored

`slashCommandsPackage`
: Your module's package for where all the Slash Commands are stored

## Information

`id`
Expand Down
100 changes: 59 additions & 41 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
plugins {
kotlin("jvm") version "2.0.0"
kotlin("plugin.serialization") version "2.0.0"
alias(libs.plugins.ktor)
// alias(libs.plugins.shadow)
id("com.gradleup.shadow")
id("one.devos.yiski.build")
java
}

Expand All @@ -16,24 +16,39 @@ repositories {
dependencies {
testImplementation(kotlin("test"))

api(shade(project(":yiski-dependencies"))!!)
shade(project(":yiski-common"))
shade(project(":yiski-module-metadata"))
shade(project(":yiski-module-loader"))

(1..6).forEach { module ->
implementation(project(":yiski$module"))
runtimeOnly(project(":yiski$module"))
}
}

tasks.test {
useJUnitPlatform()
}

kotlin {
jvmToolchain(21)
}

tasks {

jar {
manifest.attributes("Main-Class" to "one.devos.yiski.runner.YiskiRunner")
}

fatJar {
archiveFileName.set("Yiski-$version.jar")
}

test {
useJUnitPlatform()
}

}

allprojects {
apply(plugin = "java")
apply(plugin = "kotlin")
apply(plugin = "application")
apply(plugin = "io.ktor.plugin")
apply(plugin = "org.jetbrains.kotlin.plugin.serialization")

repositories {
Expand All @@ -46,47 +61,50 @@ allprojects {
}

dependencies {
if (project.name != "yiski-common" && !project.name.startsWith("yiski-module"))
implementation(project(":yiski-common"))

if (!project.name.startsWith("yiski-module")) {
implementation(project(":yiski-module-metadata"))
implementation(project(":yiski-module-loader"))
}
if (project.name != "yiski-dependencies") {
if (project.name != "yiski-common" && !project.name.startsWith("yiski-module")) {
implementation(project(":yiski-common"))
}

api(rootProject.libs.slf4j.api)
implementation(kotlin("reflect"))
implementation(rootProject.libs.bundles.exposed)
implementation(rootProject.libs.bundles.jda) {
exclude(module = "open-java")
if (!project.name.startsWith("yiski-module")) {
implementation(project(":yiski-module-metadata"))
implementation(project(":yiski-module-loader"))
}
}
implementation(rootProject.libs.bundles.ktor)
implementation(rootProject.libs.bundles.ktoml)
implementation(rootProject.libs.bundles.kotlin)
implementation(rootProject.libs.bundles.kotlinx)
implementation(rootProject.libs.bundles.lavalink)
implementation(rootProject.libs.bundles.logback)
implementation(rootProject.libs.postgresql)
implementation(rootProject.libs.kotlin.logging)
implementation(rootProject.libs.reflection)
}

// Write the version to the yiski.metadata.toml
tasks.processResources {
inputs.property("version", project.version)
tasks {
// Write the version to the yiski.metadata.toml
processResources {
inputs.property("version", project.version)

filesMatching("yiski.metadata.toml") {
expand(mutableMapOf("version" to project.version))
filesMatching("yiski.metadata.toml") {
expand(mutableMapOf("version" to project.version))
}
}
}

application {
mainClass.set("one.devos.yiski.runner.YiskiRunner")
afterEvaluate {
tasks {
if (plugins.hasPlugin("one.devos.yiski.build")) {
fatJar {
logger.lifecycle("> Moving fat JAR to modules directory")
destinationDirectory.set(rootProject.file("modules"))
}
} else {
jar {
logger.lifecycle("> Moving normal JAR to modules directory")
destinationDirectory.set(rootProject.file("modules"))
}
}
}
}
}

ktor {
fatJar {
archiveFileName.set("Yiski-${project.version}.jar")
subprojects {
dependencies {
if (project.name != "yiski-dependencies") {
implementation(project(":yiski-dependencies"))
}
}
}
}
18 changes: 18 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
plugins {
`kotlin-dsl`
}

repositories {
mavenCentral()
gradlePluginPortal()
maven("https://oss.sonatype.org/content/repositories/snapshots")
maven("https://gitlab.com/api/v4/projects/26794598/packages/maven") // Aviation GitLab
maven("https://maven.lavalink.dev/snapshots")
maven("https://maven.deftu.dev/releases")
maven("https://mvn.devos.one/snapshots")
}

dependencies {
implementation(gradleApi())
implementation("com.gradleup.shadow:shadow-gradle-plugin:8.3.0")
}
34 changes: 34 additions & 0 deletions buildSrc/src/main/kotlin/one/devos/yiski/build/BuildPlugin.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package one.devos.yiski.build

import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.tasks.SourceSetContainer
import org.gradle.api.tasks.bundling.Jar

class BuildPlugin : Plugin<Project> {

override fun apply(project: Project) {
val shade = project.configurations.create("shade")

val fatJar = project.tasks.register("fatJar", ShadowJar::class.java) {
group = "devOS"
description = "Creates a fat JAR with all dependencies"

configurations.add(shade)
manifest.inheritFrom(project.tasks.named("jar", Jar::class.java).get().manifest)
from(project.extensions.getByType(SourceSetContainer::class.java).named("main").get().output)
}

project.artifacts.add("shade", fatJar)

if (
project.plugins.hasPlugin("java") ||
project.plugins.hasPlugin("java-library") ||
project.plugins.hasPlugin("org.jetbrains.kotlin.jvm")
) {
project.tasks.named("assemble").get().dependsOn(fatJar)
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
implementation-class=one.devos.yiski.build.BuildPlugin
3 changes: 0 additions & 3 deletions drafts/plugin-loader-metadata/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ mainClass = ""
configClass = ""
[module.packages]
databasePackage = ""
slashCommandsPackage = ""

[information]
id = ""
Expand Down Expand Up @@ -79,7 +78,6 @@ mainClass = "" # Point directly to your class that uses YiskiModuleEntrypoint.
configClass = "" # Point directly to your config initializer class.
[module.packages] # Any sort of information about the module's packages.
databasePackage = "" # Optional, point directly to your Database package if you have database tables.
slashCommandsPackage = "" # Optional, point directly to your Slash Commands package if you have slash commands.

[information]
id = "" # Named ID of your Yiski Module
Expand All @@ -106,7 +104,6 @@ mainClass = "one.devos.basicmodule.BasicModule"
configClass = "one.devos.basicmodule.BasicModuleConfig"
[module.packages]
databasePackage = "one.devos.basicmodule.database"
slashCommandsPackage = "one.devos.basicmodule.commands"

[information]
id = "basicmodule"
Expand Down
1 change: 0 additions & 1 deletion drafts/plugin-loader-metadata/yiski.metadata.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ mainClass = "" # Point directly to your class that uses YiskiModuleEntrypoint.
configClass = "" # Point directly to your config initializer class.
[module.packages] # Any sort of information about the module's packages.
databasePackage = "" # Optional, point directly to your Database package if you have database tables.
slashCommandsPackage = "" # Optional, point directly to your Slash Commands package if you have slash commands.

[information]
id = "" # Named ID of your Yiski Module
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package one.devos.basicmodule

import com.akuleshov7.ktoml.file.TomlFileReader
import kotlinx.serialization.serializer
import kotlin.system.exitProcess
import one.devos.yiski.utils.TomlReader

object BasicModuleConfig {
private val configPath: String = System.getProperty("basicmodule_config", "basicmodule.config.toml")

fun loadConfig(): BasicModuleConfigData {
logger.info{ "Loading config from $configPath..." }
return try {
TomlFileReader.decodeFromFile(serializer(), configPath)
TomlReader.decodeFromFile(serializer(), configPath)
} catch (e: Exception) {
logger.error(e) { "Failed to load config" }
exitProcess(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ mainClass = "one.devos.basicmodule.BasicModule"
configClass = "one.devos.basicmodule.BasicModuleConfig"
[module.packages]
databasePackage = "one.devos.basicmodule.database"
slashCommandsPackage = "one.devos.basicmodule.commands"

[information]
id = "basicmodule"
Expand Down
5 changes: 5 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
kotlin.code.style=official

org.gradle.jvmargs=-Xmx16384m -Xms16384m -XX:MaxMetaspaceSize=1024m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.parallel.threads=12
org.gradle.parallel=true
org.gradle.daemon=false
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ include("yiski-module-metadata")
include("yiski-module-loader")

// Modules
include("yiski-dependencies")
include("yiski-common")

(1..6).forEach { module ->
Expand Down
Loading

0 comments on commit 51c1314

Please sign in to comment.