Skip to content

Dependency management

srnyx edited this page Jun 22, 2023 · 4 revisions

Similar to repository management, there are a few built-in dependencies you can use. However, it only includes Spigot-API, Spigot-NMS, and Paper. There are also some dependency handler methods added to more easily manage implemented dependencies.

Usage

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.
// It will also add all of the necessary repositories and Java version needed for the provided version.
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")
}

// For Annoying API, it will automatically exclude org.bstats:bstats-bukkit and de.tr7zw:item-nbt-api (as well as any other implemented dependencies from Annoying API) to prevent a weird duplication thing.
// Annoying API will also default to implementation configuration, instead of compileOnly.
annoyingAPI("3.0.1")

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 '{project.group}.{project.name}.libs.bstats'.
    // When using '{project.name}', it'll first replace any non-alphanumeric (including '.' and '_') with nothing to ensure a valid package.
    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 '{project.group}.{project.name}.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")
}