PlayerSync/build.gradle
laforetbrut 2361ffb272 jarJar: declare version ranges for MySQL + HikariCP
Enables co-installation with arcadia-lib2 which embeds
  HikariCP in [5.1.0, 6.0.0)
  mysql-connector-j in [8.3.0, 9.0.0)

Before: PlayerSync declared its embedded libs with no range, only the
exact version (9.3.0 / 5.1.0). When another mod declared a range that
did not include our exact version, NeoForge's jarJar resolver had no
valid overlap and would either refuse to load or arbitrary-pick one
version, risking runtime breakage.

After:
  - mysql-connector-j: strictly [8.3.0, 10.0.0), prefer 9.3.0.
    Intersects arcadia-lib's [8.3.0, 9.0.0) — resolver picks 8.3.0
    when both mods are present. 8.3.0 and 9.3.0 share the same
    Connection / PreparedStatement / ResultSet APIs we actually use,
    so downgrade is safe.
  - HikariCP: strictly [5.1.0, 6.0.0), prefer 5.1.0. Identical to
    arcadia-lib's declared range — shared single instance.

No code changes — only the metadata shipped in META-INF/jarjar/metadata.json.
Verified via unzip -p that the range is correctly emitted.
2026-04-22 06:46:24 +02:00

229 lines
8.1 KiB
Groovy

plugins {
id 'java-library'
id 'idea'
id 'maven-publish'
// id 'net.neoforged.gradle.userdev' version '7.0.170'
id 'net.neoforged.moddev'
// Adds the Kotlin Gradle plugin
id 'org.jetbrains.kotlin.jvm' version '2.2.20'
// OPTIONAL Kotlin Serialization plugin
id 'org.jetbrains.kotlin.plugin.serialization' version '2.2.20'
}
tasks.named('wrapper', Wrapper).configure {
// Define wrapper values here so as to not have to always do so when updating gradlew.properties.
// Switching this to Wrapper.DistributionType.ALL will download the full gradle sources that comes with
// documentation attached on cursor hover of gradle classes and methods. However, this comes with increased
// file size for Gradle. If you do switch this to ALL, run the Gradle wrapper task twice afterwards.
// (Verify by checking gradle/wrapper/gradle-wrapper.properties to see if distributionUrl now points to `-all`)
distributionType = Wrapper.DistributionType.BIN
}
version = minecraft_version + "-" + mod_version
group = mod_group_id
repositories {
mavenLocal()
exclusiveContent {
forRepository {
maven {
name = "Modrinth"
url = "https://api.modrinth.com/maven"
}
}
filter {
includeGroup "maven.modrinth"
}
}
exclusiveContent {
forRepository {
maven {
url "https://cursemaven.com"
}
}
filter {
includeGroup "curse.maven"
}
}
maven {
name = 'Kotlin for Forge'
url = 'https://thedarkcolour.github.io/KotlinForForge/'
}
}
base {
archivesName = mod_id
}
java.toolchain.languageVersion = JavaLanguageVersion.of(21)
// accessTransformers = project.files('src/main/resources/META-INF/accesstransformer.cfg')
neoForge {
version = project.neo_version
parchment {
mappingsVersion = project.parchment_mappings_version
minecraftVersion = project.parchment_minecraft_version
}
mods {
"${mod_id}" {
sourceSet sourceSets.main
}
}
runs {
configureEach {
systemProperty 'forge.logging.markers', 'REGISTRIES'
logLevel = org.slf4j.event.Level.DEBUG
}
client {
client()
systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id
}
server {
server()
programArgument '--nogui'
systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id
}
gameTestServer {
type = "gameTestServer"
systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id
}
data {
data()
programArguments.addAll '--mod', project.mod_id, '--all', '--output', file('src/generated/resources/').getAbsolutePath(), '--existing', file('src/main/resources/').getAbsolutePath()
}
}
}
// Sets up a dependency configuration called 'localRuntime'.
// This configuration should be used instead of 'runtimeOnly' to declare
// a dependency that will be present for runtime testing but that is
// "optional", meaning it will not be pulled by dependents of this mod.
configurations {
runtimeClasspath.extendsFrom localRuntime
}
dependencies {
implementation "net.neoforged:neoforge:${neo_version}"
compileOnly "curse.maven:curios-309927:6529130"
compileOnly "curse.maven:sophisticated-backpacks-422301:7169832"
compileOnly "curse.maven:sophisticated-core-618298:7168230"
compileOnly "curse.maven:sophisticated-storage-619320:7744168"
compileOnly "thedarkcolour:kotlinforforge:5.10.0"
compileOnly "curse.maven:cobblemon-687131:7273151"
// Mod compatibility - Cosmetic Armor Reworked
compileOnly "curse.maven:cosmetic-armor-reworked-237307:5610814"
// Mod compatibility - Apotheosis + Placebo
compileOnly "curse.maven:apotheosis-313970:7444906"
compileOnly "curse.maven:placebo-283644:6926281"
// Mod compatibility - The Aether + Accessories API
compileOnly "curse.maven:aether-255308:7043502"
compileOnly "curse.maven:accessories-938917:7046407"
// Mod compatibility - Refined Storage 2 + Extra Disks
compileOnly "curse.maven:refined-storage-243076:7610477"
compileOnly "curse.maven:extra-disks-351491:7032487"
runtimeOnly "curse.maven:curios-309927:6529130"
runtimeOnly "curse.maven:sophisticated-backpacks-422301:7169832"
runtimeOnly "curse.maven:sophisticated-core-618298:7168230"
// Embed the JDBC driver in the mod using jarJar.
// FIX COMPAT: declare a version RANGE so multi-mod setups (eg. arcadia-lib which
// requires [8.3.0, 9.0.0)) can resolve a single shared MySQL driver instance
// without jarJar complaining about incompatible constraints. The `prefer` keeps
// 9.3.0 as our baseline when PlayerSync is the only consumer.
runtimeOnly "com.mysql:mysql-connector-j:${jdbc_version}"
jarJar("com.mysql:mysql-connector-j") {
version {
strictly "[8.3.0, 10.0.0)"
prefer "${jdbc_version}"
}
}
additionalRuntimeClasspath "com.mysql:mysql-connector-j:${jdbc_version}"
// HikariCP connection pool — eliminates isValid() ping on every query (no more pingInternal in Spark)
// Exclude slf4j-api: NeoForge already ships it.
// FIX COMPAT: declare a range matching arcadia-lib's [5.1.0, 6.0.0) so jarJar
// resolution succeeds with a single shared instance.
implementation("com.zaxxer:HikariCP:${hikari_version}") {
exclude group: "org.slf4j", module: "slf4j-api"
}
jarJar("com.zaxxer:HikariCP") {
version {
strictly "[5.1.0, 6.0.0)"
prefer "${hikari_version}"
}
exclude group: "org.slf4j", module: "slf4j-api"
}
additionalRuntimeClasspath("com.zaxxer:HikariCP:${hikari_version}") {
exclude group: "org.slf4j", module: "slf4j-api"
}
// For more info:
// http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
// http://www.gradle.org/docs/current/userguide/dependency_management.html
}
// This block of code expands all declared replace properties in the specified resource targets.
// A missing property will result in an error. Properties are expanded using ${} Groovy notation.
var generateModMetadata = tasks.register("generateModMetadata", ProcessResources) {
var replaceProperties = [
minecraft_version : minecraft_version,
minecraft_version_range: minecraft_version_range,
neo_version : neo_version,
neo_version_range : neo_version_range,
loader_version_range : loader_version_range,
mod_id : mod_id,
mod_name : mod_name,
mod_license : mod_license,
mod_version : mod_version,
mod_authors : mod_authors,
mod_description : mod_description
]
inputs.properties replaceProperties
expand replaceProperties
from "src/main/templates"
into "build/generated/sources/modMetadata"
}
// Include the output of "generateModMetadata" as an input directory for the build
// this works with both building through Gradle and the IDE.
sourceSets.main.resources.srcDir generateModMetadata
// To avoid having to run "generateModMetadata" manually, make it run on every project reload
neoForge.ideSyncTask generateModMetadata
// Example configuration to allow publishing using the maven-publish plugin
publishing {
publications {
register('mavenJava', MavenPublication) {
from components.java
}
}
repositories {
maven {
url "file://${project.projectDir}/repo"
}
}
}
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation
}
// IDEA no longer automatically downloads sources/javadoc jars for dependencies, so we need to explicitly enable the behavior.
idea {
module {
downloadSources = true
downloadJavadoc = true
}
}