-
-
Notifications
You must be signed in to change notification settings - Fork 0
Dependency management
srnyx edited this page Jun 25, 2024
·
5 revisions
Similar to repository management, there are a few built-in dependencies you can use. However, it only includes Spigot-API, Spigot-NMS, Paper, Adventure, and Annoying API. There are also some dependency handler methods added to more easily manage implemented dependencies.
-
Project.spigotAPI(version: String, configuration: String = "compileOnly", configurationAction: Action<ExternalModuleDependency> = Action {})
: AddsRepository.MAVEN_CENTRAL
andRepository.SPIGOT
repositories, then addsorg.spigotmc:spigot-api
to the given configuration. Also sets the correct Java version based on the Minecraft version usinggetJavaVersionForMC(...)
-
Project.spigotNMS([version](version: String, configuration: String = "compileOnly", configurationAction: Action<ExternalModuleDependency> = Action {})
: Same as above except also adds maven local repository and addsorg.spigot:spigot
instead oforg.spigot:spigot-api
-
Project.paper(version: String, configuration: String = "compileOnly", configurationAction: Action<ExternalModuleDependency> = Action {})
: AddsRepository.MAVEN_CENTRAL
,Repository.SONATYPE_SNAPSHOTS_OLD
, andRepository.PAPER
repositories, then adds the corresponding Paper group/artificat to the given configuration -
Project.adventure(vararg dependencies: AdventureDependency, configurationAll: String? = null)
: Adds theRepository.MAVEN_CENTRAL
repository and then adds all of the given dependencies -
Project.annoyingAPI(version: String, configuration: String = "implementation", configrationAction: ExternalModuleDependency.() -> Unit = {})
: Adds theRepository.JITPACK
repository and thenxyz.srnyx:annoying-api
to the given configuration. It will also automatically relocatexyz.srnyx.annoyingapi
,org.bstats
,javassist.
,org.reflections
,de.tr7zw.changeme.nbtapi
, and any other runtime dependencies that Annoying API uses. It'll also excludenet.byteflux:libby-bukkit
andxyz.srnyx:java-utilities
to avoid them being duplicated.
Using the built-in dependencies is a bit confusing at first, but it'll make more sense the more you use it, here are some examples:
// This will add Spigot-API to compileOnly dependencies
spigotAPI("1.8.8")
// You can use any sort of dependency configuration desired and even add a configuration for it
spigotNMS("1.19.2", "implementation") {
exclude("org.bukkit")
}
// Annoying API does a bunch of stuff, see its description above for more info
annoyingAPI("3.0.1")
-
getJavaVersionForMC(minecraftVersion: String)
: Returns the required Java version for the given version of Minecraft -
getVersionString(version: String)
: Returns the version string with-R0.1-SNAPSHOT
appended to it -
<T: ModuleDependency> DependencyHandler.implementationRelocate(project: Project, dependency: T, relocateFrom: String, relocateTo: String = "${project.getPackage()}.libs.${relocateFrom.split(".").last()}", configuration: T.() -> Unit = {})
: Adds the dependency to theimplementation
configuration and relocates its classes -
DependencyHandler.implementationRelocate(project: Project, dependency: String, relocateFrom: dependency.split(":").first(), relocateTo: String = "${project.getPackage()}.libs.${relocateFrom.split(".").last()}", configuration: Action<ExternalModuleDependency> = Action {})
: Same as above, just uses different types for parameters
Making use of the custom implementation methods is also a bit strange at first, here are some examples of that:
dependencies {
// This will add bStats as an implementation dependency, as well as relocate 'org.bstats' to '{getPackage()}.libs.bstats'.
implementationRelocate(project, "org.bstats:bstats-bukkit:3.0.0")
// This is the same as above, except instead of relocating 'de.tr7zw', it'll relocate 'de.tr7zw.changeme.nbtapi' to '{getPackage()}.libs.nbtapi'.
implementationRelocate(project, "de.tr7zw:nbt-api:2.11.3", "de.tr7zw.changeme.nbtapi")
// The same as above, except it will relocate 'xyz.srnyx.annoyingapi' to 'libs.annoyingapi' instead of calculating 'from' & 'to' itself
implementationRelocate(project, "xyz.srnyx:annoying-api:3.0.1", "xyz.srnyx.annoyingapi", "libs.annoyingapi")
}
© 2023 srnyx
Thank you for using my plugin :)